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

More Related Content

What's hot (20)

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

Viewers also liked (16)

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

More from Eyal Vardi (9)

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

Recently uploaded (20)

PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 

Template syntax in Angular 2.0