Skip to content

Commit 8c64171

Browse files
committed
feat: implement content projection
1 parent fbb5e82 commit 8c64171

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

apps/angular/57-content-projection-default/src/app/app.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ import { CardComponent } from './card.component';
55
imports: [CardComponent],
66
selector: 'app-root',
77
template: `
8-
<app-card title="Titre 1" message="Message1" />
9-
<app-card title="Titre 2" />
8+
<app-card>
9+
<div class="title">Titre 1</div>
10+
<div class="message">Message1</div>
11+
</app-card>
12+
<app-card>
13+
<div class="title">Titre 2</div>
14+
<div class="message">Aucun message</div>
15+
</app-card>
1016
`,
1117
host: {
1218
class: 'p-4 block flex flex-col gap-1',
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
22

33
@Component({
44
selector: 'app-card',
55
imports: [],
66
template: `
7-
<div>{{ title() }}</div>
8-
@if (message()) {
9-
<div>{{ message() }}</div>
10-
} @else {
7+
<ng-content select=".title" />
8+
<ng-content select=".message">
119
<div>Aucun message</div>
12-
}
10+
</ng-content>
1311
`,
1412
changeDetection: ChangeDetectionStrategy.OnPush,
1513
host: {
1614
class: 'p-4 border border-grey rounded-sm flex flex-col w-[200px]',
1715
},
1816
})
19-
export class CardComponent {
20-
title = input.required<string>();
21-
message = input<string | undefined>(undefined);
22-
}
17+
export class CardComponent {}

0 commit comments

Comments
 (0)