-

-

-
+
+
-
+ @for (item of items(); track item.id) {
+
+ }
`,
standalone: true,
- imports: [NgIf, NgFor, ListItemComponent],
+ imports: [NgTemplateOutlet],
+ changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class CardComponent {
- @Input() list: any[] | null = null;
- @Input() type!: CardType;
- @Input() customClass = '';
-
- CardType = CardType;
-
- constructor(
- private teacherStore: TeacherStore,
- private studentStore: StudentStore,
- ) {}
+export class CardComponent
{
+ items = input.required();
- addNewItem() {
- if (this.type === CardType.TEACHER) {
- this.teacherStore.addOne(randTeacher());
- } else if (this.type === CardType.STUDENT) {
- this.studentStore.addOne(randStudent());
- }
- }
+ templateRef = contentChild.required('entry', { read: TemplateRef });
+ add = output();
}
diff --git a/apps/angular/1-projection/src/app/ui/list-item/list-item.component.ts b/apps/angular/1-projection/src/app/ui/list-item/list-item.component.ts
index c0f9cff7f..712f4894a 100644
--- a/apps/angular/1-projection/src/app/ui/list-item/list-item.component.ts
+++ b/apps/angular/1-projection/src/app/ui/list-item/list-item.component.ts
@@ -1,14 +1,11 @@
-import { Component, Input } from '@angular/core';
-import { StudentStore } from '../../data-access/student.store';
-import { TeacherStore } from '../../data-access/teacher.store';
-import { CardType } from '../../model/card.model';
+import { Component, output } from '@angular/core';
@Component({
selector: 'app-list-item',
template: `
- {{ name }}
-
@@ -16,20 +13,5 @@ import { CardType } from '../../model/card.model';
standalone: true,
})
export class ListItemComponent {
- @Input() id!: number;
- @Input() name!: string;
- @Input() type!: CardType;
-
- constructor(
- private teacherStore: TeacherStore,
- private studentStore: StudentStore,
- ) {}
-
- delete(id: number) {
- if (this.type === CardType.TEACHER) {
- this.teacherStore.deleteOne(id);
- } else if (this.type === CardType.STUDENT) {
- this.studentStore.deleteOne(id);
- }
- }
+ delete = output();
}