forked from tomalaforge/angular-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcity-card.component.ts
More file actions
57 lines (51 loc) · 1.42 KB
/
city-card.component.ts
File metadata and controls
57 lines (51 loc) · 1.42 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
54
55
56
57
import { Component, OnInit } from '@angular/core';
import { FakeHttpService, randomCity, randTeacher } from '../../data-access/fake-http.service';
import { CardComponent } from '../../ui/card/card.component';
import { City } from '../../model/city.model';
import { CityStore } from '../../data-access/city.store';
import { ListItemComponent } from '../../ui/list-item/list-item.component';
@Component({
selector: 'app-city-card',
template: `
<app-card
[list]="cities"
(addItem)="onAddItem()"
customClass="bg-light-orange">
<img src="assets/img/city.png" width="200px"/>
<ng-template #listItem let-item>
<app-list-item
[name]="item.name"
[id]="item.id"
(deleteItem)="onDeleteItem(item.id)"
>
</app-list-item>
</ng-template>
</app-card>
`,
styles: [
`
::ng-deep .bg-light-orange {
background-color: orange;
}
`,
],
standalone: true,
imports: [CardComponent, ListItemComponent],
})
export class CityCardComponent implements OnInit {
cities: City[] = [];
constructor(
private http: FakeHttpService,
private store: CityStore,
) {}
ngOnInit(): void {
this.http.fetchCities$.subscribe((t) => this.store.addAll(t));
this.store.cities$.subscribe((t) => (this.cities = t));
}
onAddItem(){
this.store.addOne(randomCity());
}
onDeleteItem(id: number){
this.store.deleteOne(id);
}
}