Skip to content

Commit 35e03ab

Browse files
author
Oleksandr Perepichai
committed
feat: 57 content projection default
1 parent 0d15a0b commit 35e03ab

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ 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 title>Titre 1</div>
10+
<div message>Message1</div>
11+
</app-card>
12+
<app-card>
13+
<div title>Titre 2</div>
14+
</app-card>
1015
`,
1116
host: {
1217
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]"></ng-content>
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)