SlideShare a Scribd company logo
1 of 17
Download to read offline
DATA BINDING IN 
ANGULARJS 
FROM MODEL TO VIEW 
Thomas Roch, Formedix Ltd
TYPES OF DATA BINDING 
One way (model to view) 
Two-way data binding
FROM VIEW TO MODEL 
Javascript DOM Event model: Event, KeyboardEvent, MouseEvent... 
Easy to bind model to view in Angular directives 
app.directive('input', function () { 
return { 
restrict: 'E', 
scope: false, 
link: function (scope, element, attrs) { 
element.bind('input', function (event) { 
scope.$apply(function () { 
scope.model = element.val(); 
}); 
}); 
} 
}; 
});
FROM MODEL TO VIEW 
No events or notifications fired when a value changes in EcmaScript 5 
Observers are for the future (EcmaScript 6) 
Object.observe(myObj, function observer(changes) { 
/* Do something */ 
changes.forEach(function (change) { 
console.log(change.name, change.type, change.oldValue); 
}); 
}); 
A WAY TO OVERCOME THIS: DIRTY CHECKING
WATCHERS 
// Object.observe(myObj, function observer(changes) { 
// changes.forEach(function (change) { 
// console.log(change.name, change.type, change.oldValue); 
// }); 
// }); 
$scope.$watch(watchExpression, function listener(newValue, oldValue) { 
// Do something 
console.log(newValue, oldValue); 
}); 
watchExpression can be an expression (string) 
It is evaluated in the context of the $scope using $parse 
Or it can be a function returning a value 
Watched values can be primitives, array or objects 
The listener function is executed if the watchExpression result has 
changed since the last check. 
$scope.$watch() returns a deregistration function
WATCHING DEPTHS 
$scope.$watch(watchExpr, listener) 
for watching primitives or object references 
$scope.$watchCollection(watchExpr, listener) 
for watching additions and deletions in Arrays 
$scope.$watch(watchExpr, listener, true) 
for objects and arrays equality (using angular.equals)
Credits: Tero Parviainen, http://teropa.info/blog/2014/01/26/the-three-watch-depths-of-angularjs.html
WHICH DIRECTIVES ADD WATCHERS? 
$watch: 
{{ }}, ngBind, ngBindTemplate, ngModel 
ngShow, ngHide, ngIf, ngSwitch 
ngSelected, ngChecked, ngDisabled, ngRequired, etc... 
$watchCollection: 
ngRepeat 
$watch with object equality: 
ngClass, ngStyle
THE DIGEST PROCESS 
$scope.$digest() digests a scope and its children 
Cannot run concurently 
Evaluates all watch expressions and functions 
If at least one listener is fired, it will re-evaluate all watch expressions 
The digest process stops when no more listeners have been fired 
Stops at 10 times and throws an infinite digest loop
WHAT TRIGGERS A DIGEST? 
$digest usually not called directly 
// Apply changes: execute function and call $digest 
$scope.$apply(function () { 
$scope.myModel = 'Hello'; 
}); 
Services: $http, $timeout, $interval 
Directives: ngClick, ngChange, ngFocus, ngPaste, etc... 
When inside a watch listener, no need to trigger a digest!
ISSUE #1: PERFORMANCE 
To measure performance improvements we have 
created a crude benchmark of a table of 20 columns (a 
repeater) and 100 rows (another repeater) and placed 
a binding in each cell for a total of 2000 cells. We then 
proceeded to change a small portion of the model to 
see the performance characteristics of the update. The 
result is summarized below. 
Dirty checking: 40ms 
Observers: 1-2ms
ISSUE #2: SUSTAINABILITY 
The more the watchers, the more processing required 
The more processing, the more time it takes
SOLUTION 
Limiting the number of watchers!
SCOPES AND DATA 
A variable can be available when the scope is instanciated: use of 
resolve, or synchronous initialisation 
A variable can be available after the scope is instanciated: fetching data 
asynchronously 
A variable can be changing multiple times during a scope's life
THE THREE CASES OF WATCHING DATA 
A watcher is watching... 
data available at scope creation which will never change 
data available after scope creation which will never change thereafter 
data available immediately or not, which will change once or more
DEMO
QUESTIONS

More Related Content

What's hot

Cursor
CursorCursor
Cursor
Jay Patel
ย 
Evolution of asynchrony in (ASP).NET
Evolution of asynchrony in (ASP).NETEvolution of asynchrony in (ASP).NET
Evolution of asynchrony in (ASP).NET
Aliaksandr Famin
ย 

What's hot (18)

Testing with Containers
Testing with ContainersTesting with Containers
Testing with Containers
ย 
Cursors in MySQL
Cursors in MySQL Cursors in MySQL
Cursors in MySQL
ย 
Reactive Programming on Android
Reactive Programming on AndroidReactive Programming on Android
Reactive Programming on Android
ย 
Reactive Programming no Android
Reactive Programming no AndroidReactive Programming no Android
Reactive Programming no Android
ย 
Cursor
CursorCursor
Cursor
ย 
MySQL Training
MySQL TrainingMySQL Training
MySQL Training
ย 
Java Programs
Java ProgramsJava Programs
Java Programs
ย 
Test program
Test programTest program
Test program
ย 
How to handle Dynamic Objects with OpKey?
How to handle Dynamic Objects with OpKey?How to handle Dynamic Objects with OpKey?
How to handle Dynamic Objects with OpKey?
ย 
Modify the bouncing ball example demonstrated/tutorialoutlet
Modify the bouncing ball example demonstrated/tutorialoutletModify the bouncing ball example demonstrated/tutorialoutlet
Modify the bouncing ball example demonstrated/tutorialoutlet
ย 
Async Testing giving you a sinking feeling
Async Testing giving you a sinking feelingAsync Testing giving you a sinking feeling
Async Testing giving you a sinking feeling
ย 
Redux in Angular2 for jsbe
Redux in Angular2 for jsbeRedux in Angular2 for jsbe
Redux in Angular2 for jsbe
ย 
Testing with Kotlin
Testing with KotlinTesting with Kotlin
Testing with Kotlin
ย 
The Ring programming language version 1.10 book - Part 96 of 212
The Ring programming language version 1.10 book - Part 96 of 212The Ring programming language version 1.10 book - Part 96 of 212
The Ring programming language version 1.10 book - Part 96 of 212
ย 
MS Sql Server: Doing Calculations With Functions
MS Sql Server: Doing Calculations With FunctionsMS Sql Server: Doing Calculations With Functions
MS Sql Server: Doing Calculations With Functions
ย 
R: Apply Functions
R: Apply FunctionsR: Apply Functions
R: Apply Functions
ย 
Evolution of asynchrony in (ASP).NET
Evolution of asynchrony in (ASP).NETEvolution of asynchrony in (ASP).NET
Evolution of asynchrony in (ASP).NET
ย 
Beautiful java script
Beautiful java scriptBeautiful java script
Beautiful java script
ย 

Similar to Data binding in AngularJS, from model to view

Odtug2011 adf developers make the database work for you
Odtug2011 adf developers make the database work for youOdtug2011 adf developers make the database work for you
Odtug2011 adf developers make the database work for you
Luc Bors
ย 

Similar to Data binding in AngularJS, from model to view (20)

Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJS
ย 
Building Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJavaBuilding Scalable Stateless Applications with RxJava
Building Scalable Stateless Applications with RxJava
ย 
Timedobserver
TimedobserverTimedobserver
Timedobserver
ย 
Dive into Angular, part 3: Performance
Dive into Angular, part 3: PerformanceDive into Angular, part 3: Performance
Dive into Angular, part 3: Performance
ย 
Angular 16 โ€“ the rise of Signals
Angular 16 โ€“ the rise of SignalsAngular 16 โ€“ the rise of Signals
Angular 16 โ€“ the rise of Signals
ย 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
ย 
Angular.js is super cool
Angular.js is super coolAngular.js is super cool
Angular.js is super cool
ย 
Containers & Dependency in Ember.js
Containers & Dependency in Ember.jsContainers & Dependency in Ember.js
Containers & Dependency in Ember.js
ย 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications
ย 
AngularJS, More Than Directives !
AngularJS, More Than Directives !AngularJS, More Than Directives !
AngularJS, More Than Directives !
ย 
Testing Legacy Rails Apps
Testing Legacy Rails AppsTesting Legacy Rails Apps
Testing Legacy Rails Apps
ย 
Scope.js prsentation
Scope.js prsentationScope.js prsentation
Scope.js prsentation
ย 
Odtug2011 adf developers make the database work for you
Odtug2011 adf developers make the database work for youOdtug2011 adf developers make the database work for you
Odtug2011 adf developers make the database work for you
ย 
Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014Functional UIs with Java 8 and Vaadin JavaOne2014
Functional UIs with Java 8 and Vaadin JavaOne2014
ย 
Knockout mvvm-m2-slides
Knockout mvvm-m2-slidesKnockout mvvm-m2-slides
Knockout mvvm-m2-slides
ย 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 Slides
ย 
Angular JS deep dive
Angular JS deep diveAngular JS deep dive
Angular JS deep dive
ย 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
ย 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
ย 
From Big to Massive โ€“ Scalability in AngularJS Applications
From Big to Massive โ€“ Scalability in AngularJS ApplicationsFrom Big to Massive โ€“ Scalability in AngularJS Applications
From Big to Massive โ€“ Scalability in AngularJS Applications
ย 

Recently uploaded

AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
ellan12
ย 
Call Girls Service Chandigarh Lucky โค๏ธ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky โค๏ธ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky โค๏ธ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky โค๏ธ 7710465962 Independent Call Girls In C...
Sheetaleventcompany
ย 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
SUHANI PANDEY
ย 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
singhpriety023
ย 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
sexy call girls service in goa
ย 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 ๐Ÿซฆ Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 ๐Ÿซฆ Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 ๐Ÿซฆ Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 ๐Ÿซฆ Vanshika Verma More Our Se...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
ย 
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐ŸฅตLow Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
Chandigarh Call girls 9053900678 Call girls in Chandigarh
ย 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
SUHANI PANDEY
ย 

Recently uploaded (20)

AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
ย 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
ย 
All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445
All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445
All Time Service Available Call Girls Mg Road ๐Ÿ‘Œ โญ๏ธ 6378878445
ย 
Top Rated Pune Call Girls Daund โŸŸ 6297143586 โŸŸ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund โŸŸ 6297143586 โŸŸ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund โŸŸ 6297143586 โŸŸ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund โŸŸ 6297143586 โŸŸ Call Me For Genuine Sex Servi...
ย 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
ย 
Call Girls Service Chandigarh Lucky โค๏ธ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky โค๏ธ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky โค๏ธ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky โค๏ธ 7710465962 Independent Call Girls In C...
ย 
Busty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort Service
Busty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort ServiceBusty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort Service
Busty DesiโšกCall Girls in Vasundhara Ghaziabad >เผ’8448380779 Escort Service
ย 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
ย 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
ย 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
ย 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
ย 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
ย 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
ย 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 ๐Ÿซฆ Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 ๐Ÿซฆ Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 ๐Ÿซฆ Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 ๐Ÿซฆ Vanshika Verma More Our Se...
ย 
Hireโ† Young Call Girls in Tilak nagar (Delhi) โ˜Ž๏ธ 9205541914 โ˜Ž๏ธ Independent Esc...
Hireโ† Young Call Girls in Tilak nagar (Delhi) โ˜Ž๏ธ 9205541914 โ˜Ž๏ธ Independent Esc...Hireโ† Young Call Girls in Tilak nagar (Delhi) โ˜Ž๏ธ 9205541914 โ˜Ž๏ธ Independent Esc...
Hireโ† Young Call Girls in Tilak nagar (Delhi) โ˜Ž๏ธ 9205541914 โ˜Ž๏ธ Independent Esc...
ย 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
ย 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
ย 
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐ŸฅตLow Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
Low Sexy Call Girls In Mohali 9053900678 ๐ŸฅตHave Save And Good Place ๐Ÿฅต
ย 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
ย 
Hot Call Girls |Delhi |Hauz Khas โ˜Ž 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas โ˜Ž 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas โ˜Ž 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas โ˜Ž 9711199171 Book Your One night Stand
ย 

Data binding in AngularJS, from model to view

  • 1. DATA BINDING IN ANGULARJS FROM MODEL TO VIEW Thomas Roch, Formedix Ltd
  • 2. TYPES OF DATA BINDING One way (model to view) Two-way data binding
  • 3. FROM VIEW TO MODEL Javascript DOM Event model: Event, KeyboardEvent, MouseEvent... Easy to bind model to view in Angular directives app.directive('input', function () { return { restrict: 'E', scope: false, link: function (scope, element, attrs) { element.bind('input', function (event) { scope.$apply(function () { scope.model = element.val(); }); }); } }; });
  • 4. FROM MODEL TO VIEW No events or notifications fired when a value changes in EcmaScript 5 Observers are for the future (EcmaScript 6) Object.observe(myObj, function observer(changes) { /* Do something */ changes.forEach(function (change) { console.log(change.name, change.type, change.oldValue); }); }); A WAY TO OVERCOME THIS: DIRTY CHECKING
  • 5. WATCHERS // Object.observe(myObj, function observer(changes) { // changes.forEach(function (change) { // console.log(change.name, change.type, change.oldValue); // }); // }); $scope.$watch(watchExpression, function listener(newValue, oldValue) { // Do something console.log(newValue, oldValue); }); watchExpression can be an expression (string) It is evaluated in the context of the $scope using $parse Or it can be a function returning a value Watched values can be primitives, array or objects The listener function is executed if the watchExpression result has changed since the last check. $scope.$watch() returns a deregistration function
  • 6. WATCHING DEPTHS $scope.$watch(watchExpr, listener) for watching primitives or object references $scope.$watchCollection(watchExpr, listener) for watching additions and deletions in Arrays $scope.$watch(watchExpr, listener, true) for objects and arrays equality (using angular.equals)
  • 7. Credits: Tero Parviainen, http://teropa.info/blog/2014/01/26/the-three-watch-depths-of-angularjs.html
  • 8. WHICH DIRECTIVES ADD WATCHERS? $watch: {{ }}, ngBind, ngBindTemplate, ngModel ngShow, ngHide, ngIf, ngSwitch ngSelected, ngChecked, ngDisabled, ngRequired, etc... $watchCollection: ngRepeat $watch with object equality: ngClass, ngStyle
  • 9. THE DIGEST PROCESS $scope.$digest() digests a scope and its children Cannot run concurently Evaluates all watch expressions and functions If at least one listener is fired, it will re-evaluate all watch expressions The digest process stops when no more listeners have been fired Stops at 10 times and throws an infinite digest loop
  • 10. WHAT TRIGGERS A DIGEST? $digest usually not called directly // Apply changes: execute function and call $digest $scope.$apply(function () { $scope.myModel = 'Hello'; }); Services: $http, $timeout, $interval Directives: ngClick, ngChange, ngFocus, ngPaste, etc... When inside a watch listener, no need to trigger a digest!
  • 11. ISSUE #1: PERFORMANCE To measure performance improvements we have created a crude benchmark of a table of 20 columns (a repeater) and 100 rows (another repeater) and placed a binding in each cell for a total of 2000 cells. We then proceeded to change a small portion of the model to see the performance characteristics of the update. The result is summarized below. Dirty checking: 40ms Observers: 1-2ms
  • 12. ISSUE #2: SUSTAINABILITY The more the watchers, the more processing required The more processing, the more time it takes
  • 13. SOLUTION Limiting the number of watchers!
  • 14. SCOPES AND DATA A variable can be available when the scope is instanciated: use of resolve, or synchronous initialisation A variable can be available after the scope is instanciated: fetching data asynchronously A variable can be changing multiple times during a scope's life
  • 15. THE THREE CASES OF WATCHING DATA A watcher is watching... data available at scope creation which will never change data available after scope creation which will never change thereafter data available immediately or not, which will change once or more
  • 16. DEMO