forked from tomalaforge/angular-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent-card.component.ts
More file actions
53 lines (49 loc) · 1.21 KB
/
student-card.component.ts
File metadata and controls
53 lines (49 loc) · 1.21 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 {
ChangeDetectionStrategy,
Component,
inject,
OnInit,
} from '@angular/core';
import {
FakeHttpService,
randStudent,
} from '../../data-access/fake-http.service';
import { StudentStore } from '../../data-access/student.store';
import { CardType } from '../../model/card.model';
import { CardComponent } from '../../ui/card/card.component';
@Component({
selector: 'app-student-card',
template: `
<app-card
[list]="students()"
[type]="cardType"
(addItem)="addNewItem()"
(deleteItem)="deleteItem($event)"
pictureType="webp"
customClass="bg-light-green" />
`,
styles: [
`
::ng-deep .bg-light-green {
background-color: rgba(0, 250, 0, 0.1);
}
`,
],
imports: [CardComponent],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class StudentCardComponent implements OnInit {
private http = inject(FakeHttpService);
private store = inject(StudentStore);
students = this.store.students;
cardType = CardType.STUDENT;
ngOnInit(): void {
this.http.fetchStudents$.subscribe((s) => this.store.addAll(s));
}
addNewItem() {
this.store.addOne(randStudent());
}
deleteItem(id: number) {
this.store.deleteOne(id);
}
}