File tree Expand file tree Collapse file tree
apps/angular/57-content-projection-default/src/app Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { ChangeDetectionStrategy , Component } from '@angular/core' ;
2- import { CardComponent } from './card.component' ;
2+ import { CardComponent , CardTitleComponent } from './card.component' ;
33
44@Component ( {
5- imports : [ CardComponent ] ,
5+ imports : [ CardComponent , CardTitleComponent ] ,
66 selector : 'app-root' ,
77 template : `
8- <app-card title="Titre 1" message="Message1" />
9- <app-card title="Titre 2" />
8+ <app-card message="Message1">
9+ <app-card-title>Titre 1</app-card-title>
10+ <div>Message1</div>
11+ </app-card>
12+ <app-card>
13+ <app-card-title>Titre 2</app-card-title>
14+ </app-card>
1015 ` ,
1116 host : {
1217 class : 'p-4 block flex flex-col gap-1' ,
Original file line number Diff line number Diff line change 1- import { ChangeDetectionStrategy , Component , input } from '@angular/core' ;
1+ import { ChangeDetectionStrategy , Component } from '@angular/core' ;
2+
3+ @Component ( {
4+ selector : 'app-card-title' ,
5+ template : `
6+ <ng-content></ng-content>
7+ ` ,
8+ changeDetection : ChangeDetectionStrategy . OnPush ,
9+ } )
10+ export class CardTitleComponent { }
211
312@Component ( {
413 selector : 'app-card' ,
514 imports : [ ] ,
615 template : `
7- <div>{{ title() }}</div>
8- @if (message()) {
9- <div>{{ message() }}</div>
10- } @else {
11- <div>Aucun message</div>
12- }
16+ <div>
17+ <ng-content select="app-card-title"></ng-content>
18+ </div>
19+
20+ <div>
21+ <ng-content>Aucun message</ng-content>
22+ </div>
1323 ` ,
1424 changeDetection : ChangeDetectionStrategy . OnPush ,
1525 host : {
1626 class : 'p-4 border border-grey rounded-sm flex flex-col w-[200px]' ,
1727 } ,
1828} )
19- export class CardComponent {
20- title = input . required < string > ( ) ;
21- message = input < string | undefined > ( undefined ) ;
22- }
29+ export class CardComponent { }
You can’t perform that action at this time.
0 commit comments