- @if (type() === CardType.TEACHER) {
-
![]()
- }
- @if (type() === CardType.STUDENT) {
-
![]()
- }
+
+
+
+
+
+
+
@for (item of list(); track item) {
+ [item]="item"
+ [itemTemplate]="itemTemplateRef()">
}
@@ -38,21 +35,28 @@ import { ListItemComponent } from '../list-item/list-item.component';
imports: [ListItemComponent, NgOptimizedImage],
})
export class CardComponent {
- private teacherStore = inject(TeacherStore);
- private studentStore = inject(StudentStore);
+ // private teacherStore = inject(TeacherStore);
+ // private studentStore = inject(StudentStore);
readonly list = input
(null);
- readonly type = input.required();
+ // readonly type = input.required();
readonly customClass = input('');
+ listItemDeleted = output();
+ readonly itemTemplateRef = input.required>();
+ itemAdded = output();
CardType = CardType;
addNewItem() {
- const type = this.type();
- if (type === CardType.TEACHER) {
- this.teacherStore.addOne(randTeacher());
- } else if (type === CardType.STUDENT) {
- this.studentStore.addOne(randStudent());
- }
+ this.itemAdded.emit();
+ // const type = this.type();
+ // if (type === CardType.TEACHER) {
+ // this.teacherStore.addOne(randTeacher());
+ // } else if (type === CardType.STUDENT) {
+ // this.studentStore.addOne(randStudent());
+ // }
+ }
+ deleteListItem(item: any) {
+ this.listItemDeleted.emit(item);
}
}
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 5d504f372..d2ddcc5ce 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,39 +1,47 @@
+import { CommonModule } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
- inject,
input,
+ TemplateRef,
} from '@angular/core';
-import { StudentStore } from '../../data-access/student.store';
-import { TeacherStore } from '../../data-access/teacher.store';
-import { CardType } from '../../model/card.model';
@Component({
selector: 'app-list-item',
template: `
- {{ name() }}
-
+
+
+
+
+
`,
changeDetection: ChangeDetectionStrategy.OnPush,
+ standalone: true,
+ imports: [CommonModule],
})
export class ListItemComponent {
- private teacherStore = inject(TeacherStore);
- private studentStore = inject(StudentStore);
+ // private teacherStore = inject(TeacherStore);
+ // private studentStore = inject(StudentStore);
- readonly id = input.required();
- readonly name = input.required();
- readonly type = input.required();
+ readonly item = input.required();
+ readonly itemTemplate = input.required>();
+ // itemDeleted=output();
+ // readonly type = input.required();
+ // itemDeleted=output();
- delete(id: number) {
- const type = this.type();
- if (type === CardType.TEACHER) {
- this.teacherStore.deleteOne(id);
- } else if (type === CardType.STUDENT) {
- this.studentStore.deleteOne(id);
- }
- }
+ // delete(id: number) {
+ // // const type = this.type();
+ // // if (type === CardType.TEACHER) {
+ // // this.teacherStore.deleteOne(id);
+ // // } else if (type === CardType.STUDENT) {
+ // // this.studentStore.deleteOne(id);
+ // // }
+ // this.itemDeleted.emit(id)
+ // }
}