SlideShare a Scribd company logo
1
Angular 2: A closer look to the
innovations for data binding and forms
Manfred Steyer
ManfredSteyer
Current Activities
Page  2
Software Engineering Leadership
Part-Time Studies (M.Sc.) for Manager
software-engineering-leadership.de
arJS - Deep Dive
er 2015
nings
w-jax15
November, Munich
www.jax.de
webtech conference 2015
October, Munich
www.webtechcon.de
BASTA! 2015
October, Mainz
www.basta.net
2
Goal
No general intro into Angular 2
Focusing on a specific topic
Data-Binding and Forms
Page  4
Contents
 Bindings in Angular 2
 Setting up Bindings
 DEMO: Using ng-model in Angular 2
 Handling Forms
 DEMO: Declarative Forms
Page  5
3
BINDINGS IN ANGULAR 2
Page  6
Some Goals of Angular 2
Page  7
Performance Components
Predictability
4
Data-Binding in Angular 1.x
Page  8
Model Model Directive
Nearly everything can depend on everything
Solution: Multiple Digest-Cycles
Component-Tree in Angular 2
Page  9
Component for whole App
Component (e. g. list)
Component
(e. g. list-item)
Component
(e. g. list-item)
5
Rules for Property-Bindings
 A Component only depends on its own data (and
indirectly on its parents data)
 A Component must not depend on its children data!
 Dependency Graph is a tree
 Angular only needs only one iteration („digest“)
to update tree
Page  11
Property-Binding
Page  12
model
item item
{{ item.title }} {{ item.title }}
[http://victorsavkin.com/post/110170125256/change-detection-in-angular-2]
6
Further Performance Improvements
Page  14
Immutable
Data
Observables
Event-Bindings (One-Way, Bottom/Up)
Page  16
{{ item.title }} {{ item.title }}
Event-Handler
Event-Handler
7
Event-Bindings (One-Way, Bottom/Up)
No Digest for propagating events up
But: Events can change state  Digest for
updating Property-Bindings
Page  17
Property- and Event-Bindings
Page  19
Performing
Property-Binding
Executing
Event-Handlers
Event occurs
App is ready
All Handlers executed
Properties bound
8
SETTING UP BINDINGS
Page  20
Component Controller
Page  21
@Component({
selector: 'flight-list'
})
@View({
templateUrl: 'flight-list.html',
directives: [NgFor, NgIf]
})
export class FlightList {
from: string;
to: string;
flights: Array<Flight>;
constructor(flightService: FlightService) { }
searchFlights() { [...] }
selectFlight(flight) { [...] }
}
9
View
Page  22
<table [hidden]="flights.length == 0">
<tr *ng-for="#flight of flights">
<td>{{flight.id}}</td>
<td>{{flight.date}}</td>
<td>{{flight.from}}</td>
<td>{{flight.to}}</td>
<td><a href="#" (click)="selectFlight(flight)">Select</a></td>
</tr>
</table>
<td [text-content]="flight.id"></td>
View
Page  23
<table bind-hidden="flights.length == 0">
<tr template="ng-for: var flight of flights">
<td>{{flight.id}}</td>
<td>{{flight.datum}}</td>
<td>{{flight.abflugOrt}}</td>
<td>{{flight.zielOrt}}</td>
<td><a href="#" on-click="selectFlight(flight)">Select</a></td>
</tr>
</table>
10
Recap
Property-Binding: One-Way; Top/Down
Event-Binding: One-Way; Bottom/Up
Two-Way-Binding?
Two-Way = Property-Binding + Event-Binding
Page  24
Combining Property- and Event-Bindings
Page  25
<input [ng-model]="from" (ng-model)="updateFrom($event)">
updateFrom(newValue) {
this.from = newValue;
}
11
Combining Property- and Event-Bindings
Page  26
<input [ng-model]="from" (ng-model)="from = $event">
Syntax-Sugar for „simulating“ Two-Way
Page  27
<input [(ng-model)]="from">
<input bindon-ng-model="from">
12
Types of Binding
Page  28
<input [(ng-model)]="from">
[…]
<table [hidden]="flights.length == 0">
<tr *ng-for="#flight of flights">
<td>{{flight.id}}</td>
<td>{{flight.date}}</td>
<td>{{flight.from}}</td>
<td>{{flight.to}}</td>
<td><a href="#" (click)="selectFlight(flight)">Select</a></td>
</tr>
</table>
DEMO: USING NG-MODEL
Page  29
13
HANDLING FORMS
Page  31
Approaches in Angular 2+
• ng-model
• like AngularJS 1.x
• „Forms-Controller“ is created by Angular
Declarative
• You provide „Forms-Controller“
• More control
Imperative
• You provide model
• Angular builds form dynamically
• Not implemented yet!
Data-
Driven
14
Declarative Forms
Page  33
export class FlightList {
constructor(flightService: FlightService) {
[…]
this.filter = {
from: 'Graz',
to: 'Hamburg'
};
[…]
}
}
View
Page  34
<form #f="form">
<input type="text" ng-control="from"
[(ng-model)]="filter.from" required>
<div *ng-if="!f.controls.from.valid">
…Error…
</div>
<div
*ng-if="f.controls.von.hasError('required')">
…Error…
</div>
[…]
</form>
FormDirective
f
ControlGroup
form
Control
from
15
DEMO
Page  35
Imperative Forms
export class FlightList {
filter: ControlGroup;
constructor(flightService: FlightService, fb: FormBuilder) {
[…]
this.filter = fb.group({
from: ['Graz', Validators.required],
to: ['Hamburg', Validators.required]
});
[…]
}
searchFlights() {
var filter = this.filter.value;
[…]
}
}
16
Imperative Forms
Page  37
<form [ng-form-model]="filter">
<input id="from" ng-control="from" type="text">
<div *ng-if="!filter.controls.from.valid">…Error…</div>
[…]
</form>
Summary
 Angular 2 is „fast by default“
 Two kinds of Binding
 Property Binding, 1 $digest-iteration
 Event Binding, 0 $digest-iterations
 Better Performance with immutables and observables
 Two-Way-Binding =
Property Binding + Event Binding + Syntax Sugar
Page  39
17
Summary
 Three approaches for forms
 Declarative: ng-model, like in ng1
 Imperative: more control
 Data Driven: „Forms Generator“
(not implemented yet)
Page  40
[mail] manfred.steyer@softwarearchitekt.at
[blog] www.softwarearchitekt.at
[twitter] ManfredSteyer
Contact
www.software-engineering-leadership.de

More Related Content

PDF
Multi-mania 2013: HTML5 Games to native Windows apps - attach of the yeti
Katrien De Graeve
 
PPTX
AngularJS Directives
Eyal Vardi
 
PPTX
Forms in AngularJS
Eyal Vardi
 
PDF
Angular 2 Upgrade: Migration von AngularJS 1.x zu 2.0
Manfred Steyer
 
PPTX
Big Data processing with Spark, Scala or Java?
Erik-Berndt Scheper
 
PDF
Introduction to Vaadin
netomi
 
PDF
Modern frontend development with VueJs
Tudor Barbu
 
PPTX
Tips for Angular Applications
Sebastian Pederiva
 
Multi-mania 2013: HTML5 Games to native Windows apps - attach of the yeti
Katrien De Graeve
 
AngularJS Directives
Eyal Vardi
 
Forms in AngularJS
Eyal Vardi
 
Angular 2 Upgrade: Migration von AngularJS 1.x zu 2.0
Manfred Steyer
 
Big Data processing with Spark, Scala or Java?
Erik-Berndt Scheper
 
Introduction to Vaadin
netomi
 
Modern frontend development with VueJs
Tudor Barbu
 
Tips for Angular Applications
Sebastian Pederiva
 

Similar to Data Binding and Forms in Angular 2 (20)

PPT
Java script
fahhadalghamdi
 
ODP
code-camp-meteor
meghna gogna
 
PPTX
Ruby on Rails vs ASP.NET MVC
Simone Chiaretta
 
PDF
Workshop 12: AngularJS Parte I
Visual Engineering
 
PDF
Dialogs in Android MVVM (14.11.2019)
Vladislav Ermolin
 
PDF
Quick functional UI sketches with Lua templates and mermaid.js
Alexander Gladysh
 
PPTX
practical9.pptx
LuisAlejandroTorresN1
 
PDF
How to Webpack your Django!
David Gibbons
 
PDF
Zotonic tutorial EUC 2013
Arjan
 
PDF
Strigil - lightning talks
zviri
 
PDF
The Ring programming language version 1.8 book - Part 12 of 202
Mahmoud Samir Fayed
 
PDF
Nuxeo World Session: Layouts and Content Views
Nuxeo
 
PDF
Android Jetpack - Google IO Extended Singapore 2018
Hassan Abid
 
PDF
Report from the trenches: Using SOA Integrated Gateway
Lonneke Dikmans
 
PPT
DHTML - Dynamic HTML
Reem Alattas
 
PPT
Week8
Hazen Mos
 
PDF
The newst new Router for Angular 2 - Talk at @angular_berlin, July 2016
Manfred Steyer
 
PDF
AngularJS: an introduction
Luigi De Russis
 
PDF
OgH Data Visualization Special Part III
Luc Bors
 
PDF
준비하세요 Angular js 2.0
Jeado Ko
 
Java script
fahhadalghamdi
 
code-camp-meteor
meghna gogna
 
Ruby on Rails vs ASP.NET MVC
Simone Chiaretta
 
Workshop 12: AngularJS Parte I
Visual Engineering
 
Dialogs in Android MVVM (14.11.2019)
Vladislav Ermolin
 
Quick functional UI sketches with Lua templates and mermaid.js
Alexander Gladysh
 
practical9.pptx
LuisAlejandroTorresN1
 
How to Webpack your Django!
David Gibbons
 
Zotonic tutorial EUC 2013
Arjan
 
Strigil - lightning talks
zviri
 
The Ring programming language version 1.8 book - Part 12 of 202
Mahmoud Samir Fayed
 
Nuxeo World Session: Layouts and Content Views
Nuxeo
 
Android Jetpack - Google IO Extended Singapore 2018
Hassan Abid
 
Report from the trenches: Using SOA Integrated Gateway
Lonneke Dikmans
 
DHTML - Dynamic HTML
Reem Alattas
 
Week8
Hazen Mos
 
The newst new Router for Angular 2 - Talk at @angular_berlin, July 2016
Manfred Steyer
 
AngularJS: an introduction
Luigi De Russis
 
OgH Data Visualization Special Part III
Luc Bors
 
준비하세요 Angular js 2.0
Jeado Ko
 
Ad

More from Manfred Steyer (20)

PDF
Der neue Component Router für Angular 2
Manfred Steyer
 
PDF
Datenbindung und Performance in Angular 2
Manfred Steyer
 
PDF
Single Page Applications neu gedacht: Redux in Angular 2 mit @ngrx/store
Manfred Steyer
 
PDF
Offlinefähige Browseranwendungen: Progressive Web-Apps mit Angular 2
Manfred Steyer
 
PDF
Angular 2: Die Ideen hinter Datenbindung und Formularen im Detail betrachtet
Manfred Steyer
 
PDF
Datengetriebene Web APIs mit Entity Framework
Manfred Steyer
 
PDF
Web APIs mit ASP.NET Core 1
Manfred Steyer
 
PDF
The newst new Router for Angular 2 ("Version 3")
Manfred Steyer
 
PDF
Databinding and Performance-Tuning in Angular 2
Manfred Steyer
 
PDF
Modern authentication solutions in Angular 2 with OAuth 2.0 and OpenId Connect
Manfred Steyer
 
PDF
Progressive web apps with Angular 2
Manfred Steyer
 
PDF
Der neueste neue Router (Version 3) für Angular 2
Manfred Steyer
 
PDF
Webpack
Manfred Steyer
 
PDF
ASP.NET Core 1 for MVC- and WebAPI-Devs
Manfred Steyer
 
PDF
EF Core 1: News features and changes
Manfred Steyer
 
PDF
Angular 2: Migration - SSD 2016 London
Manfred Steyer
 
PDF
Angular 2 - SSD 2016 London
Manfred Steyer
 
PDF
ASP.NET Web API Deep Dive - SSD 2016 London
Manfred Steyer
 
PDF
Was bringt Angular 2?
Manfred Steyer
 
PDF
Web APIs mit ASP.NET MVC Core 1
Manfred Steyer
 
Der neue Component Router für Angular 2
Manfred Steyer
 
Datenbindung und Performance in Angular 2
Manfred Steyer
 
Single Page Applications neu gedacht: Redux in Angular 2 mit @ngrx/store
Manfred Steyer
 
Offlinefähige Browseranwendungen: Progressive Web-Apps mit Angular 2
Manfred Steyer
 
Angular 2: Die Ideen hinter Datenbindung und Formularen im Detail betrachtet
Manfred Steyer
 
Datengetriebene Web APIs mit Entity Framework
Manfred Steyer
 
Web APIs mit ASP.NET Core 1
Manfred Steyer
 
The newst new Router for Angular 2 ("Version 3")
Manfred Steyer
 
Databinding and Performance-Tuning in Angular 2
Manfred Steyer
 
Modern authentication solutions in Angular 2 with OAuth 2.0 and OpenId Connect
Manfred Steyer
 
Progressive web apps with Angular 2
Manfred Steyer
 
Der neueste neue Router (Version 3) für Angular 2
Manfred Steyer
 
ASP.NET Core 1 for MVC- and WebAPI-Devs
Manfred Steyer
 
EF Core 1: News features and changes
Manfred Steyer
 
Angular 2: Migration - SSD 2016 London
Manfred Steyer
 
Angular 2 - SSD 2016 London
Manfred Steyer
 
ASP.NET Web API Deep Dive - SSD 2016 London
Manfred Steyer
 
Was bringt Angular 2?
Manfred Steyer
 
Web APIs mit ASP.NET MVC Core 1
Manfred Steyer
 
Ad

Recently uploaded (20)

PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
PPTX
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
PDF
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PDF
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PDF
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
PPTX
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PPTX
oapresentation.pptx
mehatdhavalrajubhai
 
DOCX
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PDF
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Presentation about variables and constant.pptx
safalsingh810
 
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
Services offered by Dynamic Solutions in Pakistan
DaniyaalAdeemShibli1
 
Become an Agentblazer Champion Challenge
Dele Amefo
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
oapresentation.pptx
mehatdhavalrajubhai
 
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 

Data Binding and Forms in Angular 2

  • 1. 1 Angular 2: A closer look to the innovations for data binding and forms Manfred Steyer ManfredSteyer Current Activities Page  2 Software Engineering Leadership Part-Time Studies (M.Sc.) for Manager software-engineering-leadership.de arJS - Deep Dive er 2015 nings w-jax15 November, Munich www.jax.de webtech conference 2015 October, Munich www.webtechcon.de BASTA! 2015 October, Mainz www.basta.net
  • 2. 2 Goal No general intro into Angular 2 Focusing on a specific topic Data-Binding and Forms Page  4 Contents  Bindings in Angular 2  Setting up Bindings  DEMO: Using ng-model in Angular 2  Handling Forms  DEMO: Declarative Forms Page  5
  • 3. 3 BINDINGS IN ANGULAR 2 Page  6 Some Goals of Angular 2 Page  7 Performance Components Predictability
  • 4. 4 Data-Binding in Angular 1.x Page  8 Model Model Directive Nearly everything can depend on everything Solution: Multiple Digest-Cycles Component-Tree in Angular 2 Page  9 Component for whole App Component (e. g. list) Component (e. g. list-item) Component (e. g. list-item)
  • 5. 5 Rules for Property-Bindings  A Component only depends on its own data (and indirectly on its parents data)  A Component must not depend on its children data!  Dependency Graph is a tree  Angular only needs only one iteration („digest“) to update tree Page  11 Property-Binding Page  12 model item item {{ item.title }} {{ item.title }} [http://victorsavkin.com/post/110170125256/change-detection-in-angular-2]
  • 6. 6 Further Performance Improvements Page  14 Immutable Data Observables Event-Bindings (One-Way, Bottom/Up) Page  16 {{ item.title }} {{ item.title }} Event-Handler Event-Handler
  • 7. 7 Event-Bindings (One-Way, Bottom/Up) No Digest for propagating events up But: Events can change state  Digest for updating Property-Bindings Page  17 Property- and Event-Bindings Page  19 Performing Property-Binding Executing Event-Handlers Event occurs App is ready All Handlers executed Properties bound
  • 8. 8 SETTING UP BINDINGS Page  20 Component Controller Page  21 @Component({ selector: 'flight-list' }) @View({ templateUrl: 'flight-list.html', directives: [NgFor, NgIf] }) export class FlightList { from: string; to: string; flights: Array<Flight>; constructor(flightService: FlightService) { } searchFlights() { [...] } selectFlight(flight) { [...] } }
  • 9. 9 View Page  22 <table [hidden]="flights.length == 0"> <tr *ng-for="#flight of flights"> <td>{{flight.id}}</td> <td>{{flight.date}}</td> <td>{{flight.from}}</td> <td>{{flight.to}}</td> <td><a href="#" (click)="selectFlight(flight)">Select</a></td> </tr> </table> <td [text-content]="flight.id"></td> View Page  23 <table bind-hidden="flights.length == 0"> <tr template="ng-for: var flight of flights"> <td>{{flight.id}}</td> <td>{{flight.datum}}</td> <td>{{flight.abflugOrt}}</td> <td>{{flight.zielOrt}}</td> <td><a href="#" on-click="selectFlight(flight)">Select</a></td> </tr> </table>
  • 10. 10 Recap Property-Binding: One-Way; Top/Down Event-Binding: One-Way; Bottom/Up Two-Way-Binding? Two-Way = Property-Binding + Event-Binding Page  24 Combining Property- and Event-Bindings Page  25 <input [ng-model]="from" (ng-model)="updateFrom($event)"> updateFrom(newValue) { this.from = newValue; }
  • 11. 11 Combining Property- and Event-Bindings Page  26 <input [ng-model]="from" (ng-model)="from = $event"> Syntax-Sugar for „simulating“ Two-Way Page  27 <input [(ng-model)]="from"> <input bindon-ng-model="from">
  • 12. 12 Types of Binding Page  28 <input [(ng-model)]="from"> […] <table [hidden]="flights.length == 0"> <tr *ng-for="#flight of flights"> <td>{{flight.id}}</td> <td>{{flight.date}}</td> <td>{{flight.from}}</td> <td>{{flight.to}}</td> <td><a href="#" (click)="selectFlight(flight)">Select</a></td> </tr> </table> DEMO: USING NG-MODEL Page  29
  • 13. 13 HANDLING FORMS Page  31 Approaches in Angular 2+ • ng-model • like AngularJS 1.x • „Forms-Controller“ is created by Angular Declarative • You provide „Forms-Controller“ • More control Imperative • You provide model • Angular builds form dynamically • Not implemented yet! Data- Driven
  • 14. 14 Declarative Forms Page  33 export class FlightList { constructor(flightService: FlightService) { […] this.filter = { from: 'Graz', to: 'Hamburg' }; […] } } View Page  34 <form #f="form"> <input type="text" ng-control="from" [(ng-model)]="filter.from" required> <div *ng-if="!f.controls.from.valid"> …Error… </div> <div *ng-if="f.controls.von.hasError('required')"> …Error… </div> […] </form> FormDirective f ControlGroup form Control from
  • 15. 15 DEMO Page  35 Imperative Forms export class FlightList { filter: ControlGroup; constructor(flightService: FlightService, fb: FormBuilder) { […] this.filter = fb.group({ from: ['Graz', Validators.required], to: ['Hamburg', Validators.required] }); […] } searchFlights() { var filter = this.filter.value; […] } }
  • 16. 16 Imperative Forms Page  37 <form [ng-form-model]="filter"> <input id="from" ng-control="from" type="text"> <div *ng-if="!filter.controls.from.valid">…Error…</div> […] </form> Summary  Angular 2 is „fast by default“  Two kinds of Binding  Property Binding, 1 $digest-iteration  Event Binding, 0 $digest-iterations  Better Performance with immutables and observables  Two-Way-Binding = Property Binding + Event Binding + Syntax Sugar Page  39
  • 17. 17 Summary  Three approaches for forms  Declarative: ng-model, like in ng1  Imperative: more control  Data Driven: „Forms Generator“ (not implemented yet) Page  40 [mail] [email protected] [blog] www.softwarearchitekt.at [twitter] ManfredSteyer Contact www.software-engineering-leadership.de