import { bootstrapApplication } from '@angular/platform-browser';
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { interval, of } from 'rxjs';
import { map, startWith, delay } from 'rxjs/operators';
@Component({
selector: 'app-root',
standalone: true,
imports: [CommonModule],
template: `
<h3>Async Pipe</h3>
<p>Time: {{ time$ | async | date:'mediumTime' }}</p>
<h4>Users (delayed)</h4>
<p *ngIf="!(users$ | async); else list">Loading...</p>
<ng-template #list>
<ul>
<li *ngFor="let u of (users$ | async)">{{ u.name }}</li>
</ul>
</ng-template>
`
})
export class App {
time$ = interval(1000).pipe(map(() => new Date()));
users$ = of([{ name: 'Alice' }, { name: 'Bob' }, { name: 'Carol' }]).pipe(delay(1200));
}
bootstrapApplication(App);
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Angular Pipes - Async</title>
</head>
<body>
<app-root></app-root>
</body>
</html>