import { bootstrapApplication } from '@angular/platform-browser';
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
standalone: true,
template: `
<h3>Null-Safe Navigation (?.)</h3>
<button (click)="toggle()">Toggle user</button>
<p>Email: {{ user?.profile?.email || '(none)' }}</p>
`
})
export class App {
user: { profile?: { email?: string } } | undefined = undefined;
toggle(){ this.user = this.user ? undefined : { profile: { email: 'a@example.com' } }; }
}
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>