Skip to content

Commit f9f66b7

Browse files
committed
feat: used content child
1 parent e34eeaa commit f9f66b7

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

apps/angular/1-projection/src/app/component/city-card/city-card.component.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ import { CardComponent } from '../../ui/card/card.component';
1717
[cardImgSrc]="'assets/img/teacher.png'"
1818
(delete)="delete($event)"
1919
(addNewItem)="addNewItem()"
20-
[nameTemplate]="customName"
21-
customClass="bg-light-red"></app-card>
22-
23-
<ng-template #customName let-item>
24-
<span class="name">{{ item.name }}</span>
25-
</ng-template>
20+
customClass="bg-light-red">
21+
<ng-template #nameTemplate let-item>
22+
<span class="name">{{ item.name }}</span>
23+
</ng-template>
24+
</app-card>
2625
`,
2726
imports: [CardComponent],
2827
changeDetection: ChangeDetectionStrategy.OnPush,

apps/angular/1-projection/src/app/ui/card/card.component.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { NgOptimizedImage, NgTemplateOutlet } from '@angular/common';
2-
import { Component, input, output, TemplateRef } from '@angular/core';
2+
import {
3+
Component,
4+
contentChild,
5+
input,
6+
output,
7+
TemplateRef,
8+
} from '@angular/core';
39
import { ListItemComponent } from '../list-item/list-item.component';
410

511
@Component({
@@ -11,7 +17,7 @@ import { ListItemComponent } from '../list-item/list-item.component';
1117
<img [ngSrc]="cardImgSrc()" width="200" height="200" priority />
1218
<section>
1319
@for (item of list(); track item) {
14-
<app-list-item [id]="item.id" (delete)="delete.emit($event)">
20+
<app-list-item [id]="item.id" (delete)="delete.emit(item.id)">
1521
<ng-container
1622
*ngTemplateOutlet="
1723
nameTemplate() || defaultName;
@@ -37,9 +43,9 @@ import { ListItemComponent } from '../list-item/list-item.component';
3743
export class CardComponent {
3844
readonly list = input<any[] | null>(null);
3945
readonly cardImgSrc = input.required<string>();
40-
readonly nameTemplate = input<TemplateRef<any>>();
4146
readonly customClass = input('');
4247

48+
nameTemplate = contentChild<TemplateRef<any>>('nameTemplate');
4349
delete = output<number>();
4450
addNewItem = output<void>();
4551
}

0 commit comments

Comments
 (0)