1683 lines
89 KiB
HTML
Raw Permalink Normal View History

<html lang="en"><head></head><body>
<form id="mainForm" method="post" action="https://run.stackblitz.com/api/angular/v1?file=src/app/app.component.html" target="_self"><input type="hidden" name="files[src/app/app.component.ts]" value="/* tslint:disable:forin member-ordering */
import { AfterViewInit, Component, ElementRef, OnInit, QueryList, ViewChildren } from '@angular/core';
import { Hero } from './hero';
export enum Color {Red, Green, Blue}
/**
* Giant grab bag of stuff to drive the chapter
*/
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements AfterViewInit, OnInit {
ngOnInit() {
this.resetHeroes();
this.setCurrentClasses();
this.setCurrentStyles();
}
ngAfterViewInit() {
// Detect effects of NgForTrackBy
trackChanges(this.heroesNoTrackBy, () => this.heroesNoTrackByCount++);
trackChanges(this.heroesWithTrackBy, () => this.heroesWithTrackByCount++);
}
@ViewChildren('noTrackBy') heroesNoTrackBy: QueryList<ElementRef>;
@ViewChildren('withTrackBy') heroesWithTrackBy: QueryList<ElementRef>;
actionName = 'Go for it';
badCurly = 'bad curly';
classes = 'special';
help = '';
alert(msg?: string) { window.alert(msg); }
callFax(value: string) { this.alert(`Faxing ${value} ...`); }
callPhone(value: string) { this.alert(`Calling ${value} ...`); }
canSave = true;
changeIds() {
this.resetHeroes();
this.heroes.forEach(h => h.id += 10 * this.heroIdIncrement++);
this.heroesWithTrackByCountReset = -1;
}
clearTrackByCounts() {
const trackByCountReset = this.heroesWithTrackByCountReset;
this.resetHeroes();
this.heroesNoTrackByCount = -1;
this.heroesWithTrackByCount = trackByCountReset;
this.heroIdIncrement = 1;
}
clicked = '';
clickMessage = '';
clickMessage2 = '';
Color = Color;
color = Color.Red;
colorToggle() {this.color = (this.color === Color.Red) ? Color.Blue : Color.Red; }
currentHero: Hero;
updateCurrentHeroName(event: Event) {
this.currentHero.name = (event.target as any).value;
}
deleteHero(hero?: Hero) {
this.alert(`Delete ${hero ? hero.name : 'the hero'}.`);
}
evilTitle = 'Template <script>alert(&quot;evil never sleeps&quot;)</script>Syntax';
fontSizePx = 16;
title = 'Template Syntax';
getVal(): number { return 2; }
name: string = Hero.heroes[0].name;
hero: Hero; // defined to demonstrate template context precedence
heroes: Hero[];
// trackBy change counting
heroesNoTrackByCount = 0;
heroesWithTrackByCount = 0;
heroesWithTrackByCountReset = 0;
heroIdIncrement = 1;
// heroImageUrl = 'https://wpclipart.com/cartoon/people/hero/hero_silhoutte_T.png';
// Public Domain terms of use: https://wpclipart.com/terms.html
heroImageUrl = 'assets/images/hero.png';
// villainImageUrl = 'https://www.clker.com/cliparts/u/s/y/L/x/9/villain-man-hi.png'
// Public Domain terms of use https://www.clker.com/disclaimer.html
villainImageUrl = 'assets/images/villain.png';
iconUrl = 'assets/images/ng-logo.png';
isActive = false;
isSpecial = true;
isUnchanged = true;
get nullHero(): Hero { return null; }
onClickMe(event?: MouseEvent) {
const evtMsg = event ? ' Event target class is ' + (event.target as HTMLElement).className : '';
this.alert('Click me.' + evtMsg);
}
onSave(event?: MouseEvent) {
const evtMsg = event ? ' Event target is ' + (event.target as HTMLElement).textContent : '';
this.alert('Saved.' + evtMsg);
if (event) { event.stopPropagation(); }
}
onSubmit(data: any) {/* referenced but not used */}
product = {
name: 'frimfram',
price: 42
};
// updates with fresh set of cloned heroes
resetHeroes() {
this.heroes = Hero.heroes.map(hero => hero.clone());
this.currentHero = this.heroes[0];
this.hero = this.currentHero;
this.heroesWithTrackByCountReset = 0;
}
setUppercaseName(name: string) {
this.currentHero.name = name.toUpperCase();
}
currentClasses: {};
setCurrentClasses() {
// CSS classes: added/removed per current state of component properties
this.currentClasses = {
saveable: this.canSave,
modified: !this.isUnchanged,
special: this.isSpecial
};
}
currentStyles: {};
setCurrentStyles() {
// CSS styles: set per current state of component properties
this.currentStyles = {
'font-style': this.canSave ? 'italic' : 'normal',
'font-weight': !this.isUnchanged ? 'bold' : 'normal',
'font-size': this.isSpecial ? '24px' : '12px'
};
}
trackByHeroes(index: number, hero: Hero): number { return hero.id; }
trackById(index: number, item: any): number { return item.id; }
}
// helper to track changes to viewChildren
function trackChanges(views: QueryList<ElementRef>, changed: () => void) {
let oldRefs = views.toArray();
views.changes.subscribe((changes: QueryList<ElementRef>) => {
const changedRefs = changes.toArray();
// Check if every changed Element is the same as old and in the same position
const isSame = oldRefs.every((v, i) => v.nativeElement === changedRefs[i].nativeElement);
if (!isSame) {
oldRefs = changedRefs;
// wait a tick because called after views are constructed
setTimeout(changed, 0);
}
});
}
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/app/app.module.1.ts]" value="import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms'; // <--- JavaScript import from Angular
/* Other imports */
@NgModule({
imports: [
BrowserModule,
FormsModule // <--- import into the NgModule
],
/* Other module metadata */
})
export class AppModule { }
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/app/app.module.ts]" value="import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { BigHeroDetailComponent, HeroDetailComponent } from './hero-detail.component';
import { ClickDirective, ClickDirective2 } from './click.directive';
import { HeroFormComponent } from './hero-form.component';
import { heroSwitchComponents } from './hero-switch.components';
import { SizerComponent } from './sizer.component';
import { SvgComponent } from './svg.component';
@NgModule({
imports: [
BrowserModule,
FormsModule
],
declarations: [
AppComponent,
BigHeroDetailComponent,
HeroDetailComponent,
HeroFormComponent,
heroSwitchComponents,
ClickDirective,
ClickDirective2,
SizerComponent,
SvgComponent
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/app/click.directive.ts]" value="/* tslint:disable directive-selector directive-class-suffix */
import { Directive, ElementRef, EventEmitter, Output } from '@angular/core';
@Directive({selector: '[myClick]'})
export class ClickDirective {
@Output('myClick') clicks = new EventEmitter<string>(); // @Output(alias) propertyName = ...
toggle = false;
constructor(el: ElementRef) {
el.nativeElement
.addEventListener('click', (event: Event) => {
this.toggle = !this.toggle;
this.clicks.emit(this.toggle ? 'Click!' : '');
});
}
}
@Directive({
selector: '[myClick2]',
// tslint:disable: no-outputs-metadata-property
outputs: ['clicks:myClick'] // propertyName:alias
})
// tslint:enable: no-outputs-metadata-property
export class ClickDirective2 {
clicks = new EventEmitter<string>();
toggle = false;
constructor(el: ElementRef) {
el.nativeElement
.addEventListener('click', (event: Event) => {
this.toggle = !this.toggle;
this.clicks.emit(this.toggle ? 'Click2!' : '');
});
}
}
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/app/hero-detail.component.ts]" value="/* tslint:disable use-input-property-decorator use-output-property-decorator */
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Hero } from './hero';
@Component({
selector: 'app-hero-detail',
// tslint:disable: no-inputs-metadata-property no-outputs-metadata-property
inputs: ['hero'],
outputs: ['deleteRequest'],
// tslint:enable: no-inputs-metadata-property no-outputs-metadata-property
styles: ['button {margin-left: 8px} div {margin: 8px 0} img {height:24px}'],
template: `
<div>
<img src=&quot;{{heroImageUrl}}&quot;>
<span [style.text-decoration]=&quot;lineThrough&quot;>
{{prefix}} {{hero?.name}}
</span>
<button (click)=&quot;delete()&quot;>Delete</button>
</div>`
})
export class HeroDetailComponent {
hero: Hero = new Hero(-1, '', 'Zzzzzzzz'); // default sleeping hero
// heroImageUrl = 'https://wpclipart.com/cartoon/people/hero/hero_silhoutte_T.png';
// Public Domain terms of use: https://wpclipart.com/terms.html
heroImageUrl = 'assets/images/hero.png';
lineThrough = '';
@Input() prefix = '';
// This component makes a request but it can't actually delete a hero.
deleteRequest = new EventEmitter<Hero>();
delete() {
this.deleteRequest.emit(this.hero);
this.lineThrough = this.lineThrough ? '' : 'line-through';
}
}
@Component({
selector: 'app-big-hero-detail',
template: `
<div class=&quot;detail&quot;>
<img src=&quot;{{heroImageUrl}}&quot;>
<div><b>{{hero?.name}}</b></div>
<div>Name: {{hero?.name}}</div>
<div>Emotion: {{hero?.emotion}}</div>
<div>Birthdate: {{hero?.birthdate | date:'longDate'}}</div>
<div>Web: <a href=&quot;{{hero?.url}}&quot; target=&quot;_blank&quot;>{{hero?.url}}</a></div>
<div>Rate/hr: {{hero?.rate | currency:'EUR'}}</div>
<br clear=&quot;all&quot;>
<button (click)=&quot;delete()&quot;>Delete</button>
</div>
`,
styles: [`
.detail { border: 1px solid black; padding: 4px; max-width: 450px; }
img { float: left; margin-right: 8px; height: 100px; }
`]
})
export class BigHeroDetailComponent extends HeroDetailComponent {
@Input() hero: Hero;
@Output() deleteRequest = new EventEmitter<Hero>();
delete() {
this.deleteRequest.emit(this.hero);
}
}
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/app/hero-form.component.ts]" value="import { Component, Input, ViewChild } from '@angular/core';
import { NgForm } from '@angular/forms';
import { Hero } from './hero';
@Component({
selector: 'app-hero-form',
templateUrl: './hero-form.component.html',
styles: [`
button { margin: 6px 0; }
#heroForm { border: 1px solid black; margin: 20px 0; padding: 8px; max-width: 350px; }
`]
})
export class HeroFormComponent {
@Input() hero: Hero;
@ViewChild('heroForm') form: NgForm;
// tslint:disable-next-line:variable-name
private _submitMessage = '';
get submitMessage() {
if (this.form &amp;&amp; !this.form.valid) {
this._submitMessage = '';
}
return this._submitMessage;
}
onSubmit(form: NgForm) {
this._submitMessage = 'Submitted. form value is ' + JSON.stringify(form.value);
}
}
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/app/hero-switch.components.ts]" value="import { Component, Input } from '@angular/core';
import { Hero } from './hero';
@Component({
selector: 'app-happy-hero',
template: `Wow. You like {{hero.name}}. What a happy hero ... just like you.`
})
export class HappyHeroComponent {
@Input() hero: Hero;
}
@Component({
selector: 'app-sad-hero',
template: `You like {{hero.name}}? Such a sad hero. Are you sad too?`
})
export class SadHeroComponent {
@Input() hero: Hero;
}
@Component({
selector: 'app-confused-hero',
template: `Are you as confused as {{hero.name}}?`
})
export class ConfusedHeroComponent {
@Input() hero: Hero;
}
@Component({
selector: 'app-unknown-hero',
template: `{{message}}`
})
export class UnknownHeroComponent {
@Input() hero: Hero;
get message() {
return this.hero &amp;&amp; this.hero.name ?
`${this.hero.name} is strange and mysterious.` :
'Are you feeling indecisive?';
}
}
export const heroSwitchComponents =
[ HappyHeroComponent, SadHeroComponent, ConfusedHeroComponent, UnknownHeroComponent ];
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/app/hero.ts]" value="export class Hero {
static nextId = 0;
static heroes: Hero[] = [
new Hero(
null,
'Hercules',
'happy',
new Date(1970, 1, 25),
'https://www.imdb.com/title/tt0065832/',
325
),
new Hero(1, 'Dr Nice', 'happy'),
new Hero(2, 'Narco', 'sad' ),
new Hero(3, 'Windstorm', 'confused' ),
new Hero(4, 'Magneta')
];
constructor(
public id?: number,
public name?: string,
public emotion?: string,
public birthdate?: Date,
public url?: string,
public rate = 100,
) {
this.id = id ? id : Hero.nextId++;
}
clone(): Hero {
return Object.assign(new Hero(), this);
}
}
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/app/sizer.component.ts]" value="import { Component, EventEmitter, Input, Output } from '@angular/core';
@Component({
selector: 'app-sizer',
template: `
<div>
<button (click)=&quot;dec()&quot; title=&quot;smaller&quot;>-</button>
<button (click)=&quot;inc()&quot; title=&quot;bigger&quot;>+</button>
<label [style.font-size.px]=&quot;size&quot;>FontSize: {{size}}px</label>
</div>`
})
export class SizerComponent {
@Input() size: number | string;
@Output() sizeChange = new EventEmitter<number>();
dec() { this.resize(-1); }
inc() { this.resize(+1); }
resize(delta: number) {
this.size = Math.min(40, Math.max(8, +this.size + delta));
this.sizeChange.emit(this.size);
}
}
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/app/svg.component.ts]" value="import { Component } from '@angular/core';
@Component({
selector: 'app-svg',
templateUrl: './svg.component.svg',
styleUrls: ['./svg.component.css']
})
export class SvgComponent {
fillColor = 'rgb(255, 0, 0)';
changeColor() {
const r = Math.floor(Math.random() * 256);
const g = Math.floor(Math.random() * 256);
const b = Math.floor(Math.random() * 256);
this.fillColor = `rgb(${r}, ${g}, ${b})`;
}
}
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/environments/environment.prod.ts]" value="export const environment = {
production: true
};
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/environments/environment.ts]" value="// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false
};
/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/main.ts]" value="import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/polyfills.ts]" value="/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called &quot;evergreen&quot; browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
*/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
* because those flags need to be set before `zone.js` being loaded, and webpack
* will put import in the top of bundle, so user need to create a separate file
* in this directory (for example: zone-flags.ts), and put the following flags
* into that file, and then add the following code before importing zone.js.
* import './zone-flags';
*
* The flags allowed in zone-flags.ts are listed here.
*
* The following flags will work for all browsers.
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch
* requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch
* specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*
* (window as any).__Zone_enable_cross_context_check = true;
*
*/
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/app/app.component.css]" value="a.to-toc { margin: 30px 0; }
button { font-size: 100%; margin: 0 2px; }
div[clickable] {cursor: pointer; max-width: 200px; margin: 16px 0}
#noTrackByCnt, #withTrackByCnt {color: darkred; max-width: 450px; margin: 4px;}
img {height: 100px;}
.box {border: 1px solid black; padding: 6px; max-width: 450px;}
.child-div {margin-left: 1em; font-weight: normal}
.context {margin-left: 1em;}
.hidden {display: none}
.parent-div {margin-top: 1em; font-weight: bold}
.special {font-weight:bold; font-size: x-large}
.bad {color: red;}
.saveable {color: limegreen;}
.curly, .modified {font-family: &quot;Brush Script MT&quot;, cursive}
.toe {margin-left: 1em; font-style: italic;}
little-hero {color:blue; font-size: smaller; background-color: Turquoise }
.to-toc {margin-top: 10px; display: block}
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/app/svg.component.css]" value="svg {
display: block;
width: 100%;
}
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/styles.css]" value="/* Global Styles */
* {
font-family: Arial, Helvetica, sans-serif;
}
h1 {
color: #264D73;
font-size: 2.5rem;
}
h2, h3 {
color: #444;
font-weight: lighter;
}
h3 {
font-size: 1.3rem;
}
body {
padding: .5rem;
max-width: 1000px;
margin: auto;
}
@media (min-width: 600px) {
body {
padding: 2rem;
}
}
body, input[text] {
color: #333;
font-family: Cambria, Georgia, serif;
}
a {
cursor: pointer;
}
button {
background-color: #eee;
border: none;
border-radius: 4px;
cursor: pointer;
color: black;
font-size: 1.2rem;
padding: 1rem;
margin-right: 1rem;
margin-bottom: 1rem;
}
button:hover {
background-color: black;
color: white;
}
button:disabled {
background-color: #eee;
color: #aaa;
cursor: auto;
}
/* Navigation link styles */
nav a {
padding: 5px 10px;
text-decoration: none;
margin-right: 10px;
margin-top: 10px;
display: inline-block;
background-color: #e8e8e8;
color: #3d3d3d;
border-radius: 4px;
}
nav a:hover {
color: white;
background-color: #42545C;
}
nav a.active {
background-color: black;
color: white;
}
hr {
margin: 1.5rem 0;
}
input[type=&quot;text&quot;] {
box-sizing: border-box;
width: 100%;
padding: .5rem;
}
/*
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
*/"><input type="hidden" name="files[src/app/app.component.html]" value="<a id=&quot;toc&quot;></a>
<h1>Template Syntax</h1>
<a href=&quot;#interpolation&quot;>Interpolation</a><br>
<a href=&quot;#expression-context&quot;>Expression context</a><br>
<a href=&quot;#statement-context&quot;>Statement context</a><br>
<a href=&quot;#mental-model&quot;>Mental Model</a><br>
<a href=&quot;#buttons&quot;>Buttons</a><br>
<a href=&quot;#prop-vs-attrib&quot;>Properties vs. Attributes</a><br>
<br>
<a href=&quot;#property-binding&quot;>Property Binding</a><br>
<div style=&quot;margin-left:8px&quot;>
<a href=&quot;#attribute-binding&quot;>Attribute Binding</a><br>
<a href=&quot;#class-binding&quot;>Class Binding</a><br>
<a href=&quot;#style-binding&quot;>Style Binding</a><br>
</div>
<br>
<a href=&quot;#event-binding&quot;>Event Binding</a><br>
<a href=&quot;#two-way&quot;>Two-way Binding</a><br>
<br>
<div>Directives</div>
<div style=&quot;margin-left:8px&quot;>
<a href=&quot;#ngModel&quot;>NgModel (two-way) Binding</a><br>
<a href=&quot;#ngClass&quot;>NgClass Binding</a><br>
<a href=&quot;#ngStyle&quot;>NgStyle Binding</a><br>
<a href=&quot;#ngIf&quot;>NgIf</a><br>
<a href=&quot;#ngFor&quot;>NgFor</a><br>
<div style=&quot;margin-left:8px&quot;>
<a href=&quot;#ngFor-index&quot;>NgFor with index</a><br>
<a href=&quot;#ngFor-trackBy&quot;>NgFor with trackBy</a><br>
</div>
<a href=&quot;#ngSwitch&quot;>NgSwitch</a><br>
</div>
<br>
<a href=&quot;#ref-vars&quot;>Template reference variables</a><br>
<a href=&quot;#inputs-and-outputs&quot;>Inputs and outputs</a><br>
<a href=&quot;#pipes&quot;>Pipes</a><br>
<a href=&quot;#safe-navigation-operator&quot;>Safe navigation operator <i>?.</i></a><br>
<a href=&quot;#non-null-assertion-operator&quot;>Non-null assertion operator <i>!.</i></a><br>
<a href=&quot;#enums&quot;>Enums</a><br>
<a href=&quot;#svg-templates&quot;>SVG Templates</a><br>
<!-- Interpolation and expressions -->
<hr><h2 id=&quot;interpolation&quot;>Interpolation</h2>
<p>My current hero is {{currentHero.name}}</p>
<h3>
{{title}}
<img src=&quot;{{heroImageUrl}}&quot; style=&quot;height:30px&quot;>
</h3>
<!-- &quot;The sum of 1 + 1 is 2&quot; -->
<p>The sum of 1 + 1 is {{1 + 1}}</p>
<!-- &quot;The sum of 1 + 1 is not 4&quot; -->
<p>The sum of 1 + 1 is not {{1 + 1 + getVal()}}</p>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<hr><h2 id=&quot;expression-context&quot;>Expression context</h2>
<p>Component expression context (&amp;#123;&amp;#123;title&amp;#125;&amp;#125;, [hidden]=&quot;isUnchanged&quot;)</p>
<div class=&quot;context&quot;>
{{title}}
<span [hidden]=&quot;isUnchanged&quot;>changed</span>
</div>
<p>Template input variable expression context (let hero)</p>
<!-- template hides the following; plenty of examples later -->
<ng-template>
<div *ngFor=&quot;let hero of heroes&quot;>{{hero.name}}</div>
</ng-template>
<p>Template reference variable expression context (#heroInput)</p>
<div (keyup)=&quot;0&quot; class=&quot;context&quot;>
Type something:
<input #heroInput> {{heroInput.value}}
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<hr><h2 id=&quot;statement-context&quot;>Statement context</h2>
<p>Component statement context ( (click)=&quot;onSave() )
<div class=&quot;context&quot;>
<button (click)=&quot;deleteHero()&quot;>Delete hero</button>
</div>
<p>Template $event statement context</p>
<div class=&quot;context&quot;>
<button (click)=&quot;onSave($event)&quot;>Save</button>
</div>
<p>Template input variable statement context (let hero)</p>
<!-- template hides the following; plenty of examples later -->
<div class=&quot;context&quot;>
<button *ngFor=&quot;let hero of heroes&quot; (click)=&quot;deleteHero(hero)&quot;>{{hero.name}}</button>
</div>
<p>Template reference variable statement context (#heroForm)</p>
<div class=&quot;context&quot;>
<form #heroForm (ngSubmit)=&quot;onSubmit(heroForm)&quot;> ... </form>
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- New Mental Model -->
<hr><h2 id=&quot;mental-model&quot;>New Mental Model</h2>
<!--<img src=&quot;https://wpclipart.com/cartoon/people/hero/hero_silhoutte_T.png&quot;>-->
<!-- Public Domain terms of use: https://wpclipart.com/terms.html -->
<div class=&quot;special&quot;>Mental Model</div>
<img src=&quot;assets/images/hero.png&quot;>
<button disabled>Save</button>
<br><br>
<div>
<!-- Normal HTML -->
<div class=&quot;special&quot;>Mental Model</div>
<!-- Wow! A new element! -->
<app-hero-detail></app-hero-detail>
</div>
<br><br>
<div>
<!-- Bind button disabled state to `isUnchanged` property -->
<button [disabled]=&quot;isUnchanged&quot;>Save</button>
</div>
<br><br>
<div>
<img [src]=&quot;heroImageUrl&quot;>
<app-hero-detail [hero]=&quot;currentHero&quot;></app-hero-detail>
<div [ngClass]=&quot;{'special': isSpecial}&quot;></div>
</div>
<br><br>
<button (click)=&quot;onSave()&quot;>Save</button>
<app-hero-detail (deleteRequest)=&quot;deleteHero()&quot;></app-hero-detail>
<div (myClick)=&quot;clicked=$event&quot; clickable>click me</div>
{{clicked}}
<br><br>
<div>
Hero Name:
<input [(ngModel)]=&quot;name&quot;>
{{name}}
</div>
<br><br>
<button [attr.aria-label]=&quot;help&quot;>help</button>
<br><br>
<div [class.special]=&quot;isSpecial&quot;>Special</div>
<br><br>
<button [style.color]=&quot;isSpecial ? 'red' : 'green'&quot;>
button</button>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- property vs. attribute -->
<hr><h2 id=&quot;prop-vs-attrib&quot;>Property vs. Attribute (img examples)</h2>
<!-- examine the following <img> tag in the browser tools -->
<img src=&quot;images/ng-logo.png&quot;
[src]=&quot;heroImageUrl&quot;>
<br><br>
<img [src]=&quot;iconUrl&quot;/>
<img bind-src=&quot;heroImageUrl&quot;/>
<img [attr.src]=&quot;villainImageUrl&quot;/>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- buttons -->
<hr><h2 id=&quot;buttons&quot;>Buttons</h2>
<button>Enabled (but does nothing)</button>
<button disabled>Disabled</button>
<button disabled=false>Still disabled</button>
<br><br>
<button disabled>disabled by attribute</button>
<button [disabled]=&quot;isUnchanged&quot;>disabled by property binding</button>
<br><br>
<button bind-disabled=&quot;isUnchanged&quot; on-click=&quot;onSave($event)&quot;>Disabled Cancel</button>
<button [disabled]=&quot;!canSave&quot; (click)=&quot;onSave($event)&quot;>Enabled Save</button>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- property binding -->
<hr><h2 id=&quot;property-binding&quot;>Property Binding</h2>
<img [src]=&quot;heroImageUrl&quot;>
<button [disabled]=&quot;isUnchanged&quot;>Cancel is disabled</button>
<div [ngClass]=&quot;classes&quot;>[ngClass] binding to the classes property</div>
<app-hero-detail [hero]=&quot;currentHero&quot;></app-hero-detail>
<img bind-src=&quot;heroImageUrl&quot;>
<!-- ERROR: HeroDetailComponent.hero expects a Hero object, not the string &quot;currentHero&quot; -->
<!-- <app-hero-detail hero=&quot;currentHero&quot;></app-hero-detail> -->
<app-hero-detail prefix=&quot;You are my&quot; [hero]=&quot;currentHero&quot;></app-hero-detail>
<p><img src=&quot;{{heroImageUrl}}&quot;> is the <i>interpolated</i> image.</p>
<p><img [src]=&quot;heroImageUrl&quot;> is the <i>property bound</i> image.</p>
<p><span>&quot;{{title}}&quot; is the <i>interpolated</i> title.</span></p>
<p>&quot;<span [innerHTML]=&quot;title&quot;></span>&quot; is the <i>property bound</i> title.</p>
<!--
Angular generates warnings for these two lines as it sanitizes them
WARNING: sanitizing HTML stripped some content (see https://g.co/ng/security#xss).
-->
<p><span>&quot;{{evilTitle}}&quot; is the <i>interpolated</i> evil title.</span></p>
<p>&quot;<span [innerHTML]=&quot;evilTitle&quot;></span>&quot; is the <i>property bound</i> evil title.</p>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- attribute binding -->
<hr><h2 id=&quot;attribute-binding&quot;>Attribute Binding</h2>
<!-- create and set a colspan attribute -->
<table border=1>
<!-- expression calculates colspan=2 -->
<tr><td [attr.colspan]=&quot;1 + 1&quot;>One-Two</td></tr>
<!-- ERROR: There is no `colspan` property to set!
<tr><td colspan=&quot;{{1 + 1}}&quot;>Three-Four</td></tr>
-->
<tr><td>Five</td><td>Six</td></tr>
</table>
<br>
<!-- create and set an aria attribute for assistive technology -->
<button [attr.aria-label]=&quot;actionName&quot;>{{actionName}} with Aria</button>
<br><br>
<!-- The following effects are not discussed in the chapter -->
<div>
<!-- any use of [attr.disabled] creates the disabled attribute -->
<button [attr.disabled]=&quot;isUnchanged&quot;>Disabled</button>
<button [attr.disabled]=&quot;!isUnchanged&quot;>Disabled as well</button>
<!-- we'd have to remove it with property binding -->
<button disabled [disabled]=&quot;false&quot;>Enabled (but inert)</button>
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- class binding -->
<hr><h2 id=&quot;class-binding&quot;>Class Binding</h2>
<!-- standard class attribute setting -->
<div class=&quot;bad curly special&quot;>Bad curly special</div>
<!-- reset/override all class names with a binding -->
<div class=&quot;bad curly special&quot;
[class]=&quot;badCurly&quot;>Bad curly</div>
<!-- toggle the &quot;special&quot; class on/off with a property -->
<div [class.special]=&quot;isSpecial&quot;>The class binding is special</div>
<!-- binding to `class.special` trumps the class attribute -->
<div class=&quot;special&quot;
[class.special]=&quot;!isSpecial&quot;>This one is not so special</div>
<div bind-class.special=&quot;isSpecial&quot;>This class binding is special too</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!--style binding -->
<hr><h2 id=&quot;style-binding&quot;>Style Binding</h2>
<button [style.color]=&quot;isSpecial ? 'red': 'green'&quot;>Red</button>
<button [style.background-color]=&quot;canSave ? 'cyan': 'grey'&quot; >Save</button>
<button [style.font-size.em]=&quot;isSpecial ? 3 : 1&quot; >Big</button>
<button [style.font-size.%]=&quot;!isSpecial ? 150 : 50&quot; >Small</button>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- event binding -->
<hr><h2 id=&quot;event-binding&quot;>Event Binding</h2>
<button (click)=&quot;onSave()&quot;>Save</button>
<button on-click=&quot;onSave()&quot;>On Save</button>
<div>
<!-- `myClick` is an event on the custom `ClickDirective` -->
<div (myClick)=&quot;clickMessage=$event&quot; clickable>click with myClick</div>
{{clickMessage}}
</div>
<!-- binding to a nested component -->
<app-hero-detail (deleteRequest)=&quot;deleteHero($event)&quot; [hero]=&quot;currentHero&quot;></app-hero-detail>
<br>
<app-big-hero-detail
(deleteRequest)=&quot;deleteHero($event)&quot;
[hero]=&quot;currentHero&quot;>
</app-big-hero-detail>
<div class=&quot;parent-div&quot; (click)=&quot;onClickMe($event)&quot; clickable>Click me
<div class=&quot;child-div&quot;>Click me too!</div>
</div>
<!-- Will save only once -->
<div (click)=&quot;onSave()&quot; clickable>
<button (click)=&quot;onSave($event)&quot;>Save, no propagation</button>
</div>
<!-- Will save twice -->
<div (click)=&quot;onSave()&quot; clickable>
<button (click)=&quot;onSave()&quot;>Save w/ propagation</button>
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<hr><h2 id=&quot;two-way&quot;>Two-way Binding</h2>
<div id=&quot;two-way-1&quot;>
<app-sizer [(size)]=&quot;fontSizePx&quot;></app-sizer>
<div [style.font-size.px]=&quot;fontSizePx&quot;>Resizable Text</div>
<label>FontSize (px): <input [(ngModel)]=&quot;fontSizePx&quot;></label>
</div>
<br>
<div id=&quot;two-way-2&quot;>
<h3>De-sugared two-way binding</h3>
<app-sizer [size]=&quot;fontSizePx&quot; (sizeChange)=&quot;fontSizePx=$event&quot;></app-sizer>
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- Two way data binding unwound;
passing the changed display value to the event handler via `$event` -->
<hr><h2 id=&quot;ngModel&quot;>NgModel (two-way) Binding</h2>
<h3>Result: {{currentHero.name}}</h3>
<input [value]=&quot;currentHero.name&quot;
(input)=&quot;updateCurrentHeroName($event)&quot;>
without NgModel
<br>
<input [(ngModel)]=&quot;currentHero.name&quot;>
[(ngModel)]
<br>
<input bindon-ngModel=&quot;currentHero.name&quot;>
bindon-ngModel
<br>
<input
[ngModel]=&quot;currentHero.name&quot;
(ngModelChange)=&quot;currentHero.name=$event&quot;>
(ngModelChange)=&quot;...name=$event&quot;
<br>
<input
[ngModel]=&quot;currentHero.name&quot;
(ngModelChange)=&quot;setUppercaseName($event)&quot;>
(ngModelChange)=&quot;setUppercaseName($event)&quot;
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- NgClass binding -->
<hr><h2 id=&quot;ngClass&quot;>NgClass Binding</h2>
<p>currentClasses is {{currentClasses | json}}</p>
<div [ngClass]=&quot;currentClasses&quot;>This div is initially saveable, unchanged, and special</div>
<!-- not used in chapter -->
<br>
<label>saveable <input type=&quot;checkbox&quot; [(ngModel)]=&quot;canSave&quot;></label> |
<label>modified: <input type=&quot;checkbox&quot; [value]=&quot;!isUnchanged&quot; (change)=&quot;isUnchanged=!isUnchanged&quot;></label> |
<label>special: <input type=&quot;checkbox&quot; [(ngModel)]=&quot;isSpecial&quot;></label>
<button (click)=&quot;setCurrentClasses()&quot;>Refresh currentClasses</button>
<br><br>
<div [ngClass]=&quot;currentClasses&quot;>
This div should be {{ canSave ? &quot;&quot;: &quot;not&quot;}} saveable,
{{ isUnchanged ? &quot;unchanged&quot; : &quot;modified&quot; }} and,
{{ isSpecial ? &quot;&quot;: &quot;not&quot;}} special after clicking &quot;Refresh&quot;.</div>
<br><br>
<div [ngClass]=&quot;isSpecial ? 'special' : ''&quot;>This div is special</div>
<div class=&quot;bad curly special&quot;>Bad curly special</div>
<div [ngClass]=&quot;{'bad':false, 'curly':true, 'special':true}&quot;>Curly special</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- NgStyle binding -->
<hr><h2 id=&quot;ngStyle&quot;>NgStyle Binding</h2>
<div [style.font-size]=&quot;isSpecial ? 'x-large' : 'smaller'&quot; >
This div is x-large or smaller.
</div>
<h3>[ngStyle] binding to currentStyles - CSS property names</h3>
<p>currentStyles is {{currentStyles | json}}</p>
<div [ngStyle]=&quot;currentStyles&quot;>
This div is initially italic, normal weight, and extra large (24px).
</div>
<!-- not used in chapter -->
<br>
<label>italic: <input type=&quot;checkbox&quot; [(ngModel)]=&quot;canSave&quot;></label> |
<label>normal: <input type=&quot;checkbox&quot; [(ngModel)]=&quot;isUnchanged&quot;></label> |
<label>xlarge: <input type=&quot;checkbox&quot; [(ngModel)]=&quot;isSpecial&quot;></label>
<button (click)=&quot;setCurrentStyles()&quot;>Refresh currentStyles</button>
<br><br>
<div [ngStyle]=&quot;currentStyles&quot;>
This div should be {{ canSave ? &quot;italic&quot;: &quot;plain&quot;}},
{{ isUnchanged ? &quot;normal weight&quot; : &quot;bold&quot; }} and,
{{ isSpecial ? &quot;extra large&quot;: &quot;normal size&quot;}} after clicking &quot;Refresh&quot;.</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- NgIf binding -->
<hr><h2 id=&quot;ngIf&quot;>NgIf Binding</h2>
<app-hero-detail *ngIf=&quot;isActive&quot;></app-hero-detail>
<div *ngIf=&quot;currentHero&quot;>Hello, {{currentHero.name}}</div>
<div *ngIf=&quot;nullHero&quot;>Hello, {{nullHero.name}}</div>
<!-- NgIf binding with template (no *) -->
<ng-template [ngIf]=&quot;currentHero&quot;>Add {{currentHero.name}} with template</ng-template>
<!-- Does not show because isActive is false! -->
<div>Hero Detail removed from DOM (via template) because isActive is false</div>
<ng-template [ngIf]=&quot;isActive&quot;>
<app-hero-detail></app-hero-detail>
</ng-template>
<!-- isSpecial is true -->
<div [class.hidden]=&quot;!isSpecial&quot;>Show with class</div>
<div [class.hidden]=&quot;isSpecial&quot;>Hide with class</div>
<!-- HeroDetail is in the DOM but hidden -->
<app-hero-detail [class.hidden]=&quot;isSpecial&quot;></app-hero-detail>
<div [style.display]=&quot;isSpecial ? 'block' : 'none'&quot;>Show with style</div>
<div [style.display]=&quot;isSpecial ? 'none' : 'block'&quot;>Hide with style</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- NgFor binding -->
<hr><h2 id=&quot;ngFor&quot;>NgFor Binding</h2>
<div class=&quot;box&quot;>
<div *ngFor=&quot;let hero of heroes&quot;>{{hero.name}}</div>
</div>
<br>
<div class=&quot;box&quot;>
<!-- *ngFor w/ hero-detail Component -->
<app-hero-detail *ngFor=&quot;let hero of heroes&quot; [hero]=&quot;hero&quot;></app-hero-detail>
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<h4 id=&quot;ngFor-index&quot;>*ngFor with index</h4>
<p>with <i>semi-colon</i> separator</p>
<div class=&quot;box&quot;>
<div *ngFor=&quot;let hero of heroes; let i=index&quot;>{{i + 1}} - {{hero.name}}</div>
</div>
<p>with <i>comma</i> separator</p>
<div class=&quot;box&quot;>
<!-- Ex: &quot;1 - Hercules&quot; -->
<div *ngFor=&quot;let hero of heroes, let i=index&quot;>{{i + 1}} - {{hero.name}}</div>
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<h4 id=&quot;ngFor-trackBy&quot;>*ngFor trackBy</h4>
<button (click)=&quot;resetHeroes()&quot;>Reset heroes</button>
<button (click)=&quot;changeIds()&quot;>Change ids</button>
<button (click)=&quot;clearTrackByCounts()&quot;>Clear counts</button>
<p><i>without</i> trackBy</p>
<div class=&quot;box&quot;>
<div #noTrackBy *ngFor=&quot;let hero of heroes&quot;>({{hero.id}}) {{hero.name}}</div>
<div id=&quot;noTrackByCnt&quot; *ngIf=&quot;heroesNoTrackByCount&quot; >
Hero DOM elements change #{{heroesNoTrackByCount}} without trackBy
</div>
</div>
<p>with trackBy</p>
<div class=&quot;box&quot;>
<div #withTrackBy *ngFor=&quot;let hero of heroes; trackBy: trackByHeroes&quot;>({{hero.id}}) {{hero.name}}</div>
<div id=&quot;withTrackByCnt&quot; *ngIf=&quot;heroesWithTrackByCount&quot;>
Hero DOM elements change #{{heroesWithTrackByCount}} with trackBy
</div>
</div>
<br><br><br>
<p>with trackBy and <i>semi-colon</i> separator</p>
<div class=&quot;box&quot;>
<div *ngFor=&quot;let hero of heroes; trackBy: trackByHeroes&quot;>
({{hero.id}}) {{hero.name}}
</div>
</div>
<p>with trackBy and <i>comma</i> separator</p>
<div class=&quot;box&quot;>
<div *ngFor=&quot;let hero of heroes, trackBy: trackByHeroes&quot;>({{hero.id}}) {{hero.name}}</div>
</div>
<p>with trackBy and <i>space</i> separator</p>
<div class=&quot;box&quot;>
<div *ngFor=&quot;let hero of heroes trackBy: trackByHeroes&quot;>({{hero.id}}) {{hero.name}}</div>
</div>
<p>with <i>generic</i> trackById function</p>
<div class=&quot;box&quot;>
<div *ngFor=&quot;let hero of heroes, trackBy: trackById&quot;>({{hero.id}}) {{hero.name}}</div>
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- NgSwitch binding -->
<hr><h2 id=&quot;ngSwitch&quot;>NgSwitch Binding</h2>
<p>Pick your favorite hero</p>
<div>
<label *ngFor=&quot;let h of heroes&quot;>
<input type=&quot;radio&quot; name=&quot;heroes&quot; [(ngModel)]=&quot;currentHero&quot; [value]=&quot;h&quot;>{{h.name}}
</label>
</div>
<div [ngSwitch]=&quot;currentHero.emotion&quot;>
<app-happy-hero *ngSwitchCase=&quot;'happy'&quot; [hero]=&quot;currentHero&quot;></app-happy-hero>
<app-sad-hero *ngSwitchCase=&quot;'sad'&quot; [hero]=&quot;currentHero&quot;></app-sad-hero>
<app-confused-hero *ngSwitchCase=&quot;'confused'&quot; [hero]=&quot;currentHero&quot;></app-confused-hero>
<div *ngSwitchCase=&quot;'confused'&quot;>Are you as confused as {{currentHero.name}}?</div>
<app-unknown-hero *ngSwitchDefault [hero]=&quot;currentHero&quot;></app-unknown-hero>
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- template reference variable -->
<hr><h2 id=&quot;ref-vars&quot;>Template reference variables</h2>
<input #phone placeholder=&quot;phone number&quot;>
<!-- lots of other elements -->
<!-- phone refers to the input element; pass its `value` to an event handler -->
<button (click)=&quot;callPhone(phone.value)&quot;>Call</button>
<input ref-fax placeholder=&quot;fax number&quot;>
<button (click)=&quot;callFax(fax.value)&quot;>Fax</button>
<!-- btn refers to the button element; show its disabled state -->
<button #btn disabled [innerHTML]=&quot;'disabled by attribute: '+btn.disabled&quot;></button>
<h4>Example Form</h4>
<app-hero-form [hero]=&quot;currentHero&quot;></app-hero-form>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- inputs and output -->
<hr><h2 id=&quot;inputs-and-outputs&quot;>Inputs and Outputs</h2>
<img [src]=&quot;iconUrl&quot;/>
<button (click)=&quot;onSave()&quot;>Save</button>
<app-hero-detail [hero]=&quot;currentHero&quot; (deleteRequest)=&quot;deleteHero($event)&quot;>
</app-hero-detail>
<div (myClick)=&quot;clickMessage2=$event&quot; clickable>myClick2</div>
{{clickMessage2}}
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- Pipes -->
<hr><h2 id=&quot;pipes&quot;>Pipes</h2>
<div>Title through uppercase pipe: {{title | uppercase}}</div>
<!-- Pipe chaining: convert title to uppercase, then to lowercase -->
<div>
Title through a pipe chain:
{{title | uppercase | lowercase}}
</div>
<!-- pipe with configuration argument => &quot;February 25, 1970&quot; -->
<div>Birthdate: {{currentHero?.birthdate | date:'longDate'}}</div>
<div>{{currentHero | json}}</div>
<div>Birthdate: {{(currentHero?.birthdate | date:'longDate') | uppercase}}</div>
<div>
<!-- pipe price to USD and display the $ symbol -->
<label>Price: </label>{{product.price | currency:'USD':'symbol'}}
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- Null values and the safe navigation operator -->
<hr><h2 id=&quot;safe-navigation-operator&quot;>Safe navigation operator <i>?.</i></h2>
<div>
The title is {{title}}
</div>
<div>
The current hero's name is {{currentHero?.name}}
</div>
<div>
The current hero's name is {{currentHero.name}}
</div>
<!--
The null hero's name is {{nullHero.name}}
See console log:
TypeError: Cannot read property 'name' of null in [null]
-->
<!--No hero, div not displayed, no error -->
<div *ngIf=&quot;nullHero&quot;>The null hero's name is {{nullHero.name}}</div>
<div>
The null hero's name is {{nullHero &amp;&amp; nullHero.name}}
</div>
<div>
<!-- No hero, no problem! -->
The null hero's name is {{nullHero?.name}}
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- non-null assertion operator -->
<hr><h2 id=&quot;non-null-assertion-operator&quot;>Non-null assertion operator <i>!.</i></h2>
<div>
<!--No hero, no text -->
<div *ngIf=&quot;hero&quot;>
The hero's name is {{hero!.name}}
</div>
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- non-null assertion operator -->
<hr><h2 id=&quot;any-type-cast-function&quot;>$any type cast function <i>$any( )</i>.</h2>
<div>
<!-- Accessing an undeclared member -->
<div>
The hero's marker is {{$any(hero).marker}}
</div>
</div>
<div>
<!-- Accessing an undeclared member -->
<div>
Undeclared members is {{$any(this).member}}
</div>
</div>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!-- TODO: discuss this in the Style binding section -->
<!-- enums in bindings -->
<hr><h2 id=&quot;enums&quot;>Enums in binding</h2>
<p>
The name of the Color.Red enum is {{Color[Color.Red]}}.<br>
The current color is {{Color[color]}} and its number is {{color}}.<br>
<button [style.color]=&quot;Color[color]&quot; (click)=&quot;colorToggle()&quot;>Enum Toggle</button>
</p>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<hr><h2 id=&quot;svg-templates&quot;>SVG Templates</h2>
<app-svg></app-svg>
<a class=&quot;to-toc&quot; href=&quot;#toc&quot;>top</a>
<!--
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
-->"><input type="hidden" name="files[src/app/hero-form.component.html]" value="<div id=&quot;heroForm&quot;>
<form (ngSubmit)=&quot;onSubmit(heroForm)&quot; #heroForm=&quot;ngForm&quot;>
<div class=&quot;form-group&quot;>
<label for=&quot;name&quot;>Name
<input class=&quot;form-control&quot; name=&quot;name&quot; required [(ngModel)]=&quot;hero.name&quot;>
</label>
</div>
<button type=&quot;submit&quot; [disabled]=&quot;!heroForm.form.valid&quot;>Submit</button>
</form>
<div [hidden]=&quot;!heroForm.form.valid&quot;>
{{submitMessage}}
</div>
</div>
<!--
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
-->"><input type="hidden" name="files[src/index.html]" value="<!DOCTYPE html>
<html lang=&quot;en&quot;>
<head>
<title>Template Syntax</title>
<base href=&quot;/&quot;>
<meta charset=&quot;UTF-8&quot;>
<meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;>
</head>
<body>
<app-root></app-root>
</body>
</html>
<!--
Copyright Google LLC. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at https://angular.io/license
-->"><input type="hidden" name="files[angular.json]" value="{
&quot;$schema&quot;: &quot;./node_modules/@angular/cli/lib/config/schema.json&quot;,
&quot;version&quot;: 1,
&quot;newProjectRoot&quot;: &quot;projects&quot;,
&quot;projects&quot;: {
&quot;angular.io-example&quot;: {
&quot;projectType&quot;: &quot;application&quot;,
&quot;schematics&quot;: {
&quot;@schematics/angular:application&quot;: {
&quot;strict&quot;: true
}
},
&quot;root&quot;: &quot;&quot;,
&quot;sourceRoot&quot;: &quot;src&quot;,
&quot;prefix&quot;: &quot;app&quot;,
&quot;architect&quot;: {
&quot;build&quot;: {
&quot;builder&quot;: &quot;@angular-devkit/build-angular:browser&quot;,
&quot;options&quot;: {
&quot;outputPath&quot;: &quot;dist&quot;,
&quot;index&quot;: &quot;src/index.html&quot;,
&quot;main&quot;: &quot;src/main.ts&quot;,
&quot;polyfills&quot;: &quot;src/polyfills.ts&quot;,
&quot;tsConfig&quot;: &quot;tsconfig.app.json&quot;,
&quot;aot&quot;: true,
&quot;assets&quot;: [
&quot;src/favicon.ico&quot;,
&quot;src/assets&quot;
],
&quot;styles&quot;: [
&quot;src/styles.css&quot;
],
&quot;scripts&quot;: []
},
&quot;configurations&quot;: {
&quot;production&quot;: {
&quot;fileReplacements&quot;: [
{
&quot;replace&quot;: &quot;src/environments/environment.ts&quot;,
&quot;with&quot;: &quot;src/environments/environment.prod.ts&quot;
}
],
&quot;optimization&quot;: true,
&quot;outputHashing&quot;: &quot;all&quot;,
&quot;sourceMap&quot;: false,
&quot;namedChunks&quot;: false,
&quot;extractLicenses&quot;: true,
&quot;vendorChunk&quot;: false,
&quot;buildOptimizer&quot;: true,
&quot;budgets&quot;: [
{
&quot;type&quot;: &quot;initial&quot;,
&quot;maximumWarning&quot;: &quot;500kb&quot;,
&quot;maximumError&quot;: &quot;1mb&quot;
},
{
&quot;type&quot;: &quot;anyComponentStyle&quot;,
&quot;maximumWarning&quot;: &quot;2kb&quot;,
&quot;maximumError&quot;: &quot;4kb&quot;
}
]
}
}
},
&quot;serve&quot;: {
&quot;builder&quot;: &quot;@angular-devkit/build-angular:dev-server&quot;,
&quot;options&quot;: {
&quot;browserTarget&quot;: &quot;angular.io-example:build&quot;
},
&quot;configurations&quot;: {
&quot;production&quot;: {
&quot;browserTarget&quot;: &quot;angular.io-example:build:production&quot;
}
}
},
&quot;extract-i18n&quot;: {
&quot;builder&quot;: &quot;@angular-devkit/build-angular:extract-i18n&quot;,
&quot;options&quot;: {
&quot;browserTarget&quot;: &quot;angular.io-example:build&quot;
}
},
&quot;test&quot;: {
&quot;builder&quot;: &quot;@angular-devkit/build-angular:karma&quot;,
&quot;options&quot;: {
&quot;main&quot;: &quot;src/test.ts&quot;,
&quot;polyfills&quot;: &quot;src/polyfills.ts&quot;,
&quot;tsConfig&quot;: &quot;tsconfig.spec.json&quot;,
&quot;karmaConfig&quot;: &quot;karma.conf.js&quot;,
&quot;assets&quot;: [
&quot;src/favicon.ico&quot;,
&quot;src/assets&quot;
],
&quot;styles&quot;: [
&quot;src/styles.css&quot;
],
&quot;scripts&quot;: []
}
},
&quot;lint&quot;: {
&quot;builder&quot;: &quot;@angular-devkit/build-angular:tslint&quot;,
&quot;options&quot;: {
&quot;tsConfig&quot;: [
&quot;tsconfig.app.json&quot;,
&quot;tsconfig.spec.json&quot;,
&quot;e2e/tsconfig.json&quot;
],
&quot;exclude&quot;: [
&quot;**/node_modules/**&quot;
]
}
},
&quot;e2e&quot;: {
&quot;builder&quot;: &quot;@angular-devkit/build-angular:protractor&quot;,
&quot;options&quot;: {
&quot;protractorConfig&quot;: &quot;e2e/protractor.conf.js&quot;,
&quot;devServerTarget&quot;: &quot;angular.io-example:serve&quot;
},
&quot;configurations&quot;: {
&quot;production&quot;: {
&quot;devServerTarget&quot;: &quot;angular.io-example:serve:production&quot;
}
}
}
}
}
},
&quot;defaultProject&quot;: &quot;angular.io-example&quot;
}
"><input type="hidden" name="files[tsconfig.json]" value="{
&quot;compileOnSave&quot;: false,
&quot;compilerOptions&quot;: {
&quot;baseUrl&quot;: &quot;./&quot;,
&quot;outDir&quot;: &quot;./dist/out-tsc&quot;,
&quot;forceConsistentCasingInFileNames&quot;: true,
&quot;noImplicitReturns&quot;: true,
&quot;noFallthroughCasesInSwitch&quot;: true,
&quot;sourceMap&quot;: true,
&quot;declaration&quot;: false,
&quot;downlevelIteration&quot;: true,
&quot;experimentalDecorators&quot;: true,
&quot;moduleResolution&quot;: &quot;node&quot;,
&quot;importHelpers&quot;: true,
&quot;target&quot;: &quot;es2015&quot;,
&quot;module&quot;: &quot;es2020&quot;,
&quot;lib&quot;: [
&quot;es2018&quot;,
&quot;dom&quot;
]
},
&quot;angularCompilerOptions&quot;: {
&quot;strictInjectionParameters&quot;: true,
&quot;strictInputAccessModifiers&quot;: true,
&quot;strictTemplates&quot;: true,
&quot;enableIvy&quot;: true
}
}"><input type="hidden" name="files[src/assets/images/hero.base64.png]" value="iVBORw0KGgoAAAANSUhEUgAAAQwAAAEoCAMAAACabz+BAAAC/VBMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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ZgHLBobJx4GDBiFGXaDhyRxL2t5r9/9cqG2Koq4mEUZNoOGKAvmhuON+/fqzotER64VCIdBswk0EmgBm+umGS+3prXfZHm8JDVafJhKP0owbrbBPN4cXbA4UgmUmMksmEUoOhJAyeJJGaYJ1Wup9drA8J0zZDlcdJhQMMAWdV3Z9sRNaYs1tpEhgHh9c6m
<g>
<rect x=&quot;0&quot; y=&quot;0&quot; width=&quot;100&quot; height=&quot;100&quot; [attr.fill]=&quot;fillColor&quot; (click)=&quot;changeColor()&quot; />
<text x=&quot;120&quot; y=&quot;50&quot;>click the rectangle to change the fill color</text>
</g>
</svg>
"><input type="hidden" name="tags[0]" value="angular"><input type="hidden" name="tags[1]" value="example"><input type="hidden" name="tags[2]" value="template"><input type="hidden" name="description" value="Angular Example - Template Syntax Collection"><input type="hidden" name="dependencies" value="{&quot;@angular/animations&quot;:&quot;~11.0.1&quot;,&quot;@angular/common&quot;:&quot;~11.0.1&quot;,&quot;@angular/compiler&quot;:&quot;~11.0.1&quot;,&quot;@angular/core&quot;:&quot;~11.0.1&quot;,&quot;@angular/forms&quot;:&quot;~11.0.1&quot;,&quot;@angular/platform-browser&quot;:&quot;~11.0.1&quot;,&quot;@angular/platform-browser-dynamic&quot;:&quot;~11.0.1&quot;,&quot;@angular/router&quot;:&quot;~11.0.1&quot;,&quot;angular-in-memory-web-api&quot;:&quot;~0.11.0&quot;,&quot;rxjs&quot;:&quot;~6.6.0&quot;,&quot;tslib&quot;:&quot;^2.0.0&quot;,&quot;zone.js&quot;:&quot;~0.11.4&quot;,&quot;jasmine-core&quot;:&quot;~3.6.0&quot;,&quot;jasmine-marbles&quot;:&quot;~0.6.0&quot;}"></form>
<script>
var embedded = 'ctl=1';
var isEmbedded = window.location.search.indexOf(embedded) > -1;
if (isEmbedded) {
var form = document.getElementById('mainForm');
var action = form.action;
var actionHasParams = action.indexOf('?') > -1;
var symbol = actionHasParams ? '&' : '?'
form.action = form.action + symbol + embedded;
}
document.getElementById("mainForm").submit();
</script>
</body></html>