-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathcard.component.ts
More file actions
57 lines (51 loc) · 1.45 KB
/
card.component.ts
File metadata and controls
57 lines (51 loc) · 1.45 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 { NgTemplateOutlet } from '@angular/common';
import { Component, contentChild, input, output } from '@angular/core';
import { CardListItemTemplateDirective } from './card-list-item-template.directive';
@Component({
selector: 'app-card',
template: `
<div
class="flex w-fit flex-col gap-3 rounded-md border-2 border-black p-4"
[class]="customClass()">
<ng-content />
<section>
@for (item of list(); track item) {
<ng-container
*ngTemplateOutlet="
listItemTemplate()?.template ?? null;
context: { $implicit: item, item: item }
"></ng-container>
}
</section>
<button
class="rounded-sm border border-blue-500 bg-blue-300 p-2"
(click)="addNewItem()">
Add
</button>
</div>
`,
styles: [
`
.bg-light-red {
background-color: rgba(250, 0, 0, 0.1);
}
.bg-light-green {
background-color: rgba(0, 250, 0, 0.1);
}
.bg-light-blue {
background-color: rgba(0, 0, 250, 0.1);
}
`,
],
imports: [NgTemplateOutlet, CardListItemTemplateDirective],
})
export class CardComponent {
readonly list = input<any[] | null>(null);
readonly customClass = input('');
onAddNewItem = output<void>();
// Use contentChild to query for the directive
listItemTemplate = contentChild(CardListItemTemplateDirective);
addNewItem() {
this.onAddNewItem.emit();
}
}