Skip to content

Commit bac20a7

Browse files
feat: migrate to new control flow
1 parent 4454821 commit bac20a7

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

src/app/components/posts.component.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ import { Post } from '../data/posts';
1111
imports: [NgFor, RouterLink, DatePipe],
1212
template: `
1313
<div class="text-2xl">
14-
<div class="py-4" *ngFor="let post of posts">
15-
<a
16-
[routerLink]="['/blog', 'posts', post.attributes.slug]"
17-
class="text-gray-600"
18-
>{{ post.attributes.title }}</a
19-
>
14+
@for (post of posts; track post.slug) {
15+
<div class="py-4">
16+
<a
17+
[routerLink]="['/blog', 'posts', post.attributes.slug]"
18+
class="text-gray-600"
19+
>{{ post.attributes.title }}</a
20+
>
2021
21-
<p class="text-sm">
22-
{{ post.attributes.publishedDate | date : 'MMMM dd, yyyy' }}
23-
</p>
24-
</div>
22+
<p class="text-sm">
23+
{{ post.attributes.publishedDate | date : 'MMMM dd, yyyy' }}
24+
</p>
25+
</div>
26+
}
2527
</div>
2628
`,
2729
})

src/app/pages/blog/posts.[slug].page.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@ import { Post } from '../../data/posts';
1010
standalone: true,
1111
imports: [MarkdownComponent, AsyncPipe, NgIf, DatePipe, ReadingTimePipe],
1212
template: `
13-
<div class="flex flex-grow justify-center min-h-screen" *ngIf="post$ | async as post">
14-
<article class="w-screen max-w-4xl p-8">
15-
<h2 class="text-gray-600 text-2xl">{{ post.attributes.title }}</h2>
13+
@if (post$ | async; as post) {
14+
<div class="flex flex-grow justify-center min-h-screen">
15+
<article class="w-screen max-w-4xl p-8">
16+
<h2 class="text-gray-600 text-2xl">{{ post.attributes.title }}</h2>
1617
17-
<span class="font-light text-sm">
18-
{{ post.attributes.publishedDate | date : 'MMMM dd, yyyy' }} -
19-
{{ post.content | readingtime }} min read
20-
</span>
18+
<span class="font-light text-sm">
19+
{{ post.attributes.publishedDate | date : 'MMMM dd, yyyy' }} -
20+
{{ post.content | readingtime }} min read
21+
</span>
2122
22-
<analog-markdown [content]="post.content"></analog-markdown>
23-
</article>
24-
</div>
23+
<analog-markdown [content]="post.content"></analog-markdown>
24+
</article>
25+
</div>
26+
}
2527
`,
2628
})
2729
export default class BlogPostComponent {

0 commit comments

Comments
 (0)