Template syntax in Angular 2.0
Template syntax in Angular 2.0
System
shim
ZoneReflectRx
Libraries
Application
<todo-list [source]="todos"
(selected-change)="update($event)" />
core & common
Angular Frameworks
Router Http Compiler Platform
@Component({
selector: 'todo-list',
styles: [`
.done{
text-decoration: line-through;
color: grey;
}`],
template: `
<ul class="list-unstyled">
<li *ngFor="#todo of todos">
<input type="checkbox" [(ngModel)]="todo.done">
<span [class.done]="todo.done">{{todo.text}}</span>
</li>
</ul>`
})
export class TodoList {
@Output() selectedChange = new EventEmitter()
@Input('source') todos: Todo[] = [];
constructor(private db:Db, private proxy:Proxy){}
}
<h3>My First Angular Application</h3>
<h3>
{{title}}
<img src = "{{heroImageUrl}}" >
</h3>
first evaluates and
then converts to a
string.
<p>
Employer: {{ employer?.companyName }}
</p>
<todo-list [source]="expression" ></todo-list>
<todo-list (click)="statement" ></todo-list>
<todo-list (click)="task = $event" ></todo-list>
<div (click)="clickMessage = $event">...</div>
deleted = new EventEmitter<User>();
onDelete() { this.deleted.emit(this.user); }
<user-detail (deleted)="onUserDeleted($event)"></user-detail>
Template syntax in Angular 2.0
Template syntax in Angular 2.0
Template syntax in Angular 2.0
<img src="{{heroImageUrl}}">
<img [src]="'' + heroImageUrl">
<div>The title is {{title}}</div>
<div [textContent]="'The title is ' + title"></div>
<tr><td colspan="{{1 + 1}}">Three-Four</td></tr>
Template parse errors:
Can't bind to 'colspan' since it isn't a known native property
<!-- expression calculates colspan=2 -->
<tr><td [attr.colspan]="1 + 1">One-Two</td></tr>
Target Sample
Property [property] = "expression"
Event (event) = "expression"
Two-Way [(ngModel)] = "expression"
Attribute [attr.aria-label] = "expression"
Class [class.special] = "expression"
Style [style.color] = "expression"
Template syntax in Angular 2.0
<!-- toggle the "special" class on/off with a property -->
<div [class.special]="isSpecial">
The class binding is special
</div>
<div [ngClass]="setClasses()">...</div>
setClasses() {
return {
modified: !this.isUnchanged, // false
special : this.isSpecial, // true
}
}
<div [style.fontSize]="isSpecial ? 'x-large' : 'smaller'" >
This div is x-large
</div>
<div [ngStyle]="setStyles()">...</div>
setStyles() {
return {
'font-style': this.canSave ? 'italic' : 'normal',
'font-weight': !this.isUnchanged ? 'bold' : 'normal',
'font-size': this.isSpecial ? '24px' : '8px',
}
}
<div *ngIf="currentUser">
Hello, {{currentUser.firstName}}
</div>
<span [ngSwitch]="toeChoice">
<template [ngSwitchWhen]="'Eenie'"> Eenie </template>
<template [ngSwitchWhen]="'Meanie'">Meanie </template>
<template [ngSwitchWhen]="'Miney'"> Miney </template>
<template [ngSwitchWhen]="'Moe'"> Moe </template>
<template ngSwitchDefault> Other </template>
</span>
<div *ngFor="let user of users; #i=index"> {{user.fullName}}
</div>
Creates a local template
variable.
We can capture the
index in a local template
variable
<li
*ngFor="let item of items;
let i = index;
trackBy: trackByFn">
...
</li>
<template
ngFor
let-item
[ngForOf]="items"
let-i="index"
[ngForTrackBy]="trackByFn">
<li>...</li>
</template>
<!-- phone refers to the input element -->
<input #phone placeholder="phone number">
<button (click)="callPhone(phone.value)">Call</button>
<!-- fax refers to the input element -->
<input ref-fax placeholder="fax number">
<button (click)="callFax(fax.value)">Fax</button>
Developer guides
Angular code source
Template syntax in Angular 2.0

More Related Content

PPTX
Angular 2 Architecture
PPTX
Angular 1.x vs. Angular 2.x
PPTX
Angular 2 - Ahead of-time Compilation
PPTX
Angular 2 Architecture (Bucharest 26/10/2016)
PPTX
Http Communication in Angular 2.0
PPTX
Modules and injector
PPTX
Routing And Navigation
PPTX
Performance Optimization In Angular 2
Angular 2 Architecture
Angular 1.x vs. Angular 2.x
Angular 2 - Ahead of-time Compilation
Angular 2 Architecture (Bucharest 26/10/2016)
Http Communication in Angular 2.0
Modules and injector
Routing And Navigation
Performance Optimization In Angular 2

What's hot (20)

PPTX
Component lifecycle hooks in Angular 2.0
PPTX
AngularJS Compile Process
PPTX
AngularJS $Provide Service
PPTX
Angular 2.0 Pipes
PPTX
Upgrading from Angular 1.x to Angular 2.x
PPTX
Angular 2.0 forms
PPTX
Angular 2.0 Views
PPTX
Angular 2 NgModule
PPTX
AngularJS Internal
PPTX
AngularJS - $http & $resource Services
PPTX
Angular 2.0 Dependency injection
PPTX
AngularJS Services
PDF
Databinding and Performance-Tuning in Angular 2
PPTX
AngularJs $provide API internals & circular dependency problem.
PPTX
Workshop 1: Good practices in JavaScript
PPTX
AngularJS Directives
PPTX
AngularJS Architecture
PPTX
AngularJS Routing
PDF
AngularJS Basics with Example
PDF
Workshop 12: AngularJS Parte I
Component lifecycle hooks in Angular 2.0
AngularJS Compile Process
AngularJS $Provide Service
Angular 2.0 Pipes
Upgrading from Angular 1.x to Angular 2.x
Angular 2.0 forms
Angular 2.0 Views
Angular 2 NgModule
AngularJS Internal
AngularJS - $http & $resource Services
Angular 2.0 Dependency injection
AngularJS Services
Databinding and Performance-Tuning in Angular 2
AngularJs $provide API internals & circular dependency problem.
Workshop 1: Good practices in JavaScript
AngularJS Directives
AngularJS Architecture
AngularJS Routing
AngularJS Basics with Example
Workshop 12: AngularJS Parte I
Ad

Viewers also liked (16)

PPTX
Async & Parallel in JavaScript
PPTX
Angular 2.0 Routing and Navigation
PPTX
Node.js File system & Streams
PPTX
Node.js Socket.IO
PPTX
Node.js Event Emitter
PPTX
Node js overview
PPTX
Introducing Razor - A new view engine for ASP.NET
PPTX
Razor and the Art of Templating
PPTX
Views
PDF
Nodejs
PPTX
Node.js Spplication Scaling
PPTX
The Promised Land (in Angular)
PPTX
Async Frontiers
PDF
Boom! Promises/A+ Was Born
PPTX
AngulrJS Overview
PPTX
Modules in ECMAScript 6.0
Async & Parallel in JavaScript
Angular 2.0 Routing and Navigation
Node.js File system & Streams
Node.js Socket.IO
Node.js Event Emitter
Node js overview
Introducing Razor - A new view engine for ASP.NET
Razor and the Art of Templating
Views
Nodejs
Node.js Spplication Scaling
The Promised Land (in Angular)
Async Frontiers
Boom! Promises/A+ Was Born
AngulrJS Overview
Modules in ECMAScript 6.0
Ad

More from Eyal Vardi (9)

PPTX
Why magic
PPTX
Smart Contract
PDF
Rachel's grandmother's recipes
PPTX
Proxies in ECMAScript 6.0
PPTX
Iterators & Generators in ECMAScript 6.0
PPTX
Symbols in ECMAScript 6.0
PPTX
Objects & Classes in ECMAScript 6.0
PPTX
Scope & Functions in ECMAScript 6.0
PPTX
Node.js Express
Why magic
Smart Contract
Rachel's grandmother's recipes
Proxies in ECMAScript 6.0
Iterators & Generators in ECMAScript 6.0
Symbols in ECMAScript 6.0
Objects & Classes in ECMAScript 6.0
Scope & Functions in ECMAScript 6.0
Node.js Express

Recently uploaded (20)

PDF
AI Guide for Business Growth - Arna Softech
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PPTX
Airline CRS | Airline CRS Systems | CRS System
PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
PPTX
MLforCyber_MLDataSetsandFeatures_Presentation.pptx
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PPTX
most interesting chapter in the world ppt
PDF
BoxLang Dynamic AWS Lambda - Japan Edition
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PDF
novaPDF Pro 11.9.482 Crack + License Key [Latest 2025]
PDF
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
PPTX
Download Adobe Photoshop Crack 2025 Free
PPTX
Cybersecurity: Protecting the Digital World
PDF
Type Class Derivation in Scala 3 - Jose Luis Pintado Barbero
PDF
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
PDF
Topaz Photo AI Crack New Download (Latest 2025)
PPTX
How to Odoo 19 Installation on Ubuntu - CandidRoot
DOCX
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
PPTX
Tech Workshop Escape Room Tech Workshop
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
AI Guide for Business Growth - Arna Softech
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
Airline CRS | Airline CRS Systems | CRS System
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
MLforCyber_MLDataSetsandFeatures_Presentation.pptx
Wondershare Recoverit Full Crack New Version (Latest 2025)
most interesting chapter in the world ppt
BoxLang Dynamic AWS Lambda - Japan Edition
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
novaPDF Pro 11.9.482 Crack + License Key [Latest 2025]
Top 10 Software Development Trends to Watch in 2025 🚀.pdf
Download Adobe Photoshop Crack 2025 Free
Cybersecurity: Protecting the Digital World
Type Class Derivation in Scala 3 - Jose Luis Pintado Barbero
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
Topaz Photo AI Crack New Download (Latest 2025)
How to Odoo 19 Installation on Ubuntu - CandidRoot
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
Tech Workshop Escape Room Tech Workshop
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev

Template syntax in Angular 2.0