-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathpage-2.ts
54 lines (50 loc) · 1.17 KB
/
page-2.ts
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
import { httpResource } from '@angular/common/http';
import {
ChangeDetectionStrategy,
Component,
ResourceStatus,
signal,
} from '@angular/core';
import { ExpandableCard } from './expandable-card';
interface Post {
id: number;
title: string;
body: string;
userId: number;
}
@Component({
selector: 'app-page-2',
template: `
page2
<app-expandable-card [(isExpanded)]="isExpanded">
<div title>Load Post</div>
<div>
@if (postRessource.isLoading()) {
Loading...
} @else if (postRessource.status() === ResourceStatus.Error) {
Error...
} @else {
@for (post of postRessource.value(); track post.id) {
<div>{{ post.title }}</div>
}
}
</div>
</app-expandable-card>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [ExpandableCard],
})
export class Page2 {
protected readonly ResourceStatus = ResourceStatus;
public postRessource = httpResource<Post[]>(
() => {
return this.isExpanded()
? 'https://jsonplaceholder.typicode.com/posts'
: undefined;
},
{
defaultValue: [],
},
);
isExpanded = signal(false);
}