SlideShare a Scribd company logo
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
Ad

Recommended

Angular 2 Architecture
Angular 2 Architecture
Eyal Vardi
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
Eyal Vardi
 
Angular 2 - Ahead of-time Compilation
Angular 2 - Ahead of-time Compilation
Eyal Vardi
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
Eyal Vardi
 
Http Communication in Angular 2.0
Http Communication in Angular 2.0
Eyal Vardi
 
Modules and injector
Modules and injector
Eyal Vardi
 
Routing And Navigation
Routing And Navigation
Eyal Vardi
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2
Eyal Vardi
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
Eyal Vardi
 
AngularJS Compile Process
AngularJS Compile Process
Eyal Vardi
 
AngularJS $Provide Service
AngularJS $Provide Service
Eyal Vardi
 
Angular 2.0 Pipes
Angular 2.0 Pipes
Eyal Vardi
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
Eyal Vardi
 
Angular 2.0 forms
Angular 2.0 forms
Eyal Vardi
 
Angular 2.0 Views
Angular 2.0 Views
Eyal Vardi
 
Angular 2 NgModule
Angular 2 NgModule
Eyal Vardi
 
AngularJS Internal
AngularJS Internal
Eyal Vardi
 
AngularJS - $http & $resource Services
AngularJS - $http & $resource Services
Eyal Vardi
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injection
Eyal Vardi
 
AngularJS Services
AngularJS Services
Eyal Vardi
 
Databinding and Performance-Tuning in Angular 2
Databinding and Performance-Tuning in Angular 2
Manfred Steyer
 
AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.
Yan Yankowski
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
Visual Engineering
 
AngularJS Directives
AngularJS Directives
Eyal Vardi
 
AngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
AngularJS Routing
AngularJS Routing
Eyal Vardi
 
AngularJS Basics with Example
AngularJS Basics with Example
Sergey Bolshchikov
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
Visual Engineering
 
Async & Parallel in JavaScript
Async & Parallel in JavaScript
Eyal Vardi
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
Eyal Vardi
 

More Related Content

What's hot (20)

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

Viewers also liked (16)

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

More from Eyal Vardi (9)

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

Recently uploaded (20)

Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Simplify Insurance Regulations with Compliance Management Software
Simplify Insurance Regulations with Compliance Management Software
Insurance Tech Services
 
Humans vs AI Call Agents - Qcall.ai's Special Report
Humans vs AI Call Agents - Qcall.ai's Special Report
Udit Goenka
 
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
 
AI for PV: Development and Governance for a Regulated Industry
AI for PV: Development and Governance for a Regulated Industry
Biologit
 
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
 
Streamlining CI/CD with FME Flow: A Practical Guide
Streamlining CI/CD with FME Flow: A Practical Guide
Safe Software
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
University Campus Navigation for All - Peak of Data & AI
University Campus Navigation for All - Peak of Data & AI
Safe Software
 
Download Adobe Illustrator Crack free for Windows 2025?
Download Adobe Illustrator Crack free for Windows 2025?
grete1122g
 
From Data Preparation to Inference: How Alluxio Speeds Up AI
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Digital Transformation: Automating the Placement of Medical Interns
Digital Transformation: Automating the Placement of Medical Interns
Safe Software
 
A Guide to Telemedicine Software Development.pdf
A Guide to Telemedicine Software Development.pdf
Olivero Bozzelli
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
How Automation in Claims Handling Streamlined Operations
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Simplify Insurance Regulations with Compliance Management Software
Simplify Insurance Regulations with Compliance Management Software
Insurance Tech Services
 
Humans vs AI Call Agents - Qcall.ai's Special Report
Humans vs AI Call Agents - Qcall.ai's Special Report
Udit Goenka
 
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
 
AI for PV: Development and Governance for a Regulated Industry
AI for PV: Development and Governance for a Regulated Industry
Biologit
 
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
 
Streamlining CI/CD with FME Flow: A Practical Guide
Streamlining CI/CD with FME Flow: A Practical Guide
Safe Software
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
University Campus Navigation for All - Peak of Data & AI
University Campus Navigation for All - Peak of Data & AI
Safe Software
 
Download Adobe Illustrator Crack free for Windows 2025?
Download Adobe Illustrator Crack free for Windows 2025?
grete1122g
 
From Data Preparation to Inference: How Alluxio Speeds Up AI
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
 
Zoneranker’s Digital marketing solutions
Zoneranker’s Digital marketing solutions
reenashriee
 
Digital Transformation: Automating the Placement of Medical Interns
Digital Transformation: Automating the Placement of Medical Interns
Safe Software
 
A Guide to Telemedicine Software Development.pdf
A Guide to Telemedicine Software Development.pdf
Olivero Bozzelli
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
MOVIE RECOMMENDATION SYSTEM, UDUMULA GOPI REDDY, Y24MC13085.pptx
Maharshi Mallela
 
How Automation in Claims Handling Streamlined Operations
How Automation in Claims Handling Streamlined Operations
Insurance Tech Services
 

Template syntax in Angular 2.0