Skip to content

Commit 24907c9

Browse files
authored
docs: simplify BlogComponent by removing NgFor & NgIf (#1953)
1 parent 8c503d2 commit 24907c9

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

apps/docs-app/docs/features/routing/content.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ To get a list using the list of content files in the `src/content` folder, use t
254254
import { Component } from '@angular/core';
255255
import { RouterLink, RouterOutlet } from '@angular/router';
256256
import { injectContentFiles } from '@analogjs/content';
257-
import { NgFor } from '@angular/common';
258257

259258
export interface PostAttributes {
260259
title: string;
@@ -265,14 +264,18 @@ export interface PostAttributes {
265264

266265
@Component({
267266
standalone: true,
268-
imports: [RouterOutlet, RouterLink, NgFor],
267+
imports: [RouterOutlet, RouterLink],
269268
template: `
270269
<ul>
271-
<li *ngFor="let post of posts">
272-
<a [routerLink]="['/blog', 'posts', post.slug]">{{
273-
post.attributes.title
274-
}}</a>
275-
</li>
270+
@for (post of posts; track post.slug) {
271+
<li>
272+
<a [routerLink]="['/blog', 'posts', post.slug]">
273+
{{ post.attributes.title }}
274+
</a>
275+
</li>
276+
} @empty {
277+
<li>No posts yet.</li>
278+
}
276279
</ul>
277280
`,
278281
})
@@ -292,7 +295,7 @@ The `injectContent()` function uses the `slug` route parameter by default to get
292295
```ts
293296
// /src/app/pages/blog/posts.[slug].page.ts
294297
import { injectContent, MarkdownComponent } from '@analogjs/content';
295-
import { AsyncPipe, NgIf } from '@angular/common';
298+
import { AsyncPipe } from '@angular/common';
296299
import { Component } from '@angular/core';
297300

298301
export interface PostAttributes {
@@ -304,12 +307,12 @@ export interface PostAttributes {
304307

305308
@Component({
306309
standalone: true,
307-
imports: [MarkdownComponent, AsyncPipe, NgIf],
310+
imports: [MarkdownComponent, AsyncPipe],
308311
template: `
309-
<ng-container *ngIf="post$ | async as post">
312+
@if (post$ | async; as post) {
310313
<h1>{{ post.attributes.title }}</h1>
311314
<analog-markdown [content]="post.content"></analog-markdown>
312-
</ng-container>
315+
}
313316
`,
314317
})
315318
export default class BlogPostComponent {
@@ -429,12 +432,12 @@ export interface ProjectAttributes {
429432

430433
@Component({
431434
standalone: true,
432-
imports: [MarkdownComponent, AsyncPipe, NgIf],
435+
imports: [MarkdownComponent, AsyncPipe],
433436
template: `
434-
<ng-container *ngIf="project$ | async as project">
437+
@if (project$ | async; as project) {
435438
<h1>{{ project.attributes.title }}</h1>
436439
<analog-markdown [content]="project.content"></analog-markdown>
437-
</ng-container>
440+
}
438441
`,
439442
})
440443
export default class ProjectComponent {

0 commit comments

Comments
 (0)