-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathteacher-card.component.ts
More file actions
53 lines (47 loc) · 1.37 KB
/
teacher-card.component.ts
File metadata and controls
53 lines (47 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { NgOptimizedImage } from '@angular/common';
import { Component, inject, OnInit } from '@angular/core';
import {
FakeHttpService,
randTeacher,
} from '../../data-access/fake-http.service';
import { TeacherStore } from '../../data-access/teacher.store';
import { CardType } from '../../model/card.model';
import { Teacher } from '../../model/teacher.model';
import { CardComponent } from '../../ui/card/card.component';
@Component({
selector: 'app-teacher-card',
template: `
<app-card
(itemDeleted)="onDelete($event)"
(itemAdded)="onAdd()"
[list]="teachers()"
[displayNameFn]="displayNameFn"
customClass="bg-light-red">
<img ngSrc="assets/img/teacher.png" width="200" height="200" alt="" />
</app-card>
`,
styles: [
`
::ng-deep .bg-light-red {
background-color: rgba(250, 0, 0, 0.1);
}
`,
],
imports: [CardComponent, NgOptimizedImage],
})
export class TeacherCardComponent implements OnInit {
private http = inject(FakeHttpService);
public store = inject(TeacherStore);
teachers = this.store.teachers;
cardType = CardType.TEACHER;
ngOnInit(): void {
this.http.fetchTeachers$.subscribe((t) => this.store.addAll(t));
}
displayNameFn = (teacher: Teacher) => teacher.firstName;
onDelete(id: number) {
this.store.deleteOne(id);
}
onAdd() {
this.store.addOne(randTeacher());
}
}