Skip to content

Commit 0a7b9e7

Browse files
committed
feat(58): solution 58 content projection condition
1 parent ec0f415 commit 0a7b9e7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

apps/angular/58-content-projection-condition/src/app/card.component.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1+
import { NgTemplateOutlet } from '@angular/common';
12
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
23

34
@Component({
45
selector: 'app-card',
56
template: `
67
@if (small()) {
7-
<ng-content select="[title]" />
8-
<ng-content select="[message]" />
8+
<ng-container [ngTemplateOutlet]="titleTmpl" />
9+
<ng-container [ngTemplateOutlet]="bodyTmpl" />
910
} @else {
1011
<div class="p-4">
1112
<div class="text-2xl">
12-
<ng-content select="[title]" />
13+
<ng-container [ngTemplateOutlet]="titleTmpl" />
1314
</div>
14-
<ng-content select="[message]" />
15+
<ng-container [ngTemplateOutlet]="bodyTmpl" />
1516
</div>
1617
}
18+
19+
<ng-template #titleTmpl>
20+
<ng-content select="[title]" />
21+
</ng-template>
22+
23+
<ng-template #bodyTmpl>
24+
<ng-content select="[message]" />
25+
</ng-template>
1726
`,
1827
changeDetection: ChangeDetectionStrategy.OnPush,
1928
host: {
2029
class: 'p-4 border border-grey rounded-sm flex flex-col w-[200px]',
2130
},
31+
imports: [NgTemplateOutlet],
2232
})
2333
export class CardComponent {
2434
small = input<boolean>(false);

0 commit comments

Comments
 (0)