forked from tomalaforge/angular-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcard.component.ts
More file actions
57 lines (53 loc) · 1.71 KB
/
card.component.ts
File metadata and controls
57 lines (53 loc) · 1.71 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 { NgOptimizedImage, NgTemplateOutlet } from '@angular/common';
import { Component, input, output } from '@angular/core';
import { CardType } from '../../model/card.model';
import { ListItemComponent } from '../list-item/list-item.component';
@Component({
selector: 'app-card',
template: `
<ng-template #card let-cardTypeVal="cardType">
<div
class="flex w-fit flex-col gap-3 rounded-md border-2 border-black p-4"
[class]="customClass()">
<img
ngSrc="assets/img/{{ CardType[cardTypeVal()].toLowerCase() }}.{{
this.pictureType()
}}"
width="200"
height="200"
priority />
<section>
@for (item of list(); track item) {
<app-list-item
[name]="item.name"
[firstName]="item.firstName"
[lastName]="item.lastName"
[id]="item.id"
[type]="type()"
(deleteItem)="delete($event)" />
}
</section>
<button
class="rounded-sm border border-blue-500 bg-blue-300 p-2"
(click)="addItem.emit()">
Add
</button>
</div>
</ng-template>
<ng-container *ngTemplateOutlet="card; context: ctx"></ng-container>
`,
imports: [ListItemComponent, NgOptimizedImage, NgTemplateOutlet],
})
export class CardComponent {
readonly list = input<any[] | null>(null);
readonly type = input.required<CardType>();
readonly customClass = input('');
readonly pictureType = input.required<string>();
addItem = output<void>();
deleteItem = output<number>();
readonly ctx = { cardType: this.type };
CardType = CardType;
delete(id: number) {
this.deleteItem.emit(id);
}
}