import { bootstrapApplication } from '@angular/platform-browser';
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-root',
standalone: true,
imports: [CommonModule],
template: `
<h3>*ngIf with as</h3>
<button (click)="toggle()">Toggle user</button>
<p *ngIf="user as u; else empty">Hello {{ u.name }}!</p>
<ng-template #empty>No user</ng-template>
`
})
export class App {
user: { name: string } | null = { name: 'Ada' };
toggle(){ this.user = this.user ? null : { name: 'Ada' }; }
}
bootstrapApplication(App);
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Angular Templates</title>
</head>
<body>
<app-root></app-root>
</body>
</html>