My First Angular Application
Interpolation
My current hero is {{currentHero.firstName}}
{{title}}
The sum of 1 + 1 is {{1 + 1}}
The sum of 1 + 1 is not {{1+1+getVal()}}
New Mental Model
Mental Model
{{currentHero.fullName}}
click me
{{clicked}}
Hero Name: {{heroName}}
Special
kebab-case
Property vs. Attribute (img examples)
Buttons
Property Binding
NgClass is special
The title is {{title}}
Attribute Binding
Class Binding
Bad curly special
Bad curly
The class binding is special
This one is not so special
This class binding is special too
Style Binding
Event Binding
click with my-click
{{clickity}}
NgModel Binding
Result: {{currentHero.firstName}}
without NgModel
[(ng-model)]
bindon-ng-model
(ng-model-change) = "...firstName=$event"
(ng-model-change) = "setUpperCaseFirstName($event)"
NgClass Binding
setClasses returns {{setClasses() | json}}
This div is saveable and special
After setClasses(), the classes are "{{classDiv.className}}"
This div is special
Bad curly special
Curly special
NgStyle Binding
This div is x-large
setStyles returns {{setStyles() | json}}
This div is italic, normal weight, and x-large
After setStyles(), the styles are "{{getStyles(styleDiv)}}"
NgIf Binding
Hello, {{currentHero.firstName}}
Hello, {{nullHero.firstName}}
Add {{currentHero.firstName}} with template
Hero Detail removed from DOM (via template) because isActive is false
Show with class
Hide with class
Show with style
Hide with style
NgSwitch Binding
You picked
Eenie
Meanie
Miney
Moe
Other
NgFor Binding
{{i+1}} - {{hero.fullName}}
* and Template
NgIf expansion
NgFor expansion
Template local variables
Example Form
Inputs and Outputs
my-click2
{{clicked2}}
Pipes
{{ title | uppercase }}
{{ title | uppercase | lowercase }}
Birthdate: {{currentHero?.birthdate | date:'longDate'}}
{{currentHero | json}}
Birthdate: {{(currentHero?.birthdate | date:'longDate') | uppercase}}
{{product.price | currency:'USD':true}}
Elvis
The title is {{ title }}
The current hero's name is {{currentHero?.firstName}}
The current hero's name is {{currentHero.firstName}}
The null hero's name is {{nullHero.firstName}}
The null hero's name is {{nullHero && nullHero.firstName}}
The null hero's name is {{nullHero?.firstName}}
Enums in binding
The name of the Color.Red enum is {{Color[Color.Red]}}
The current color number is {{color}}