SlideShare a Scribd company logo
AngularJS Architecture
HTML
Browser
Static
DOM
Dynamic
DOM
(View)
AngularJS
DOM
Content
Loaded
Event
ng-app=“module”
$injector
$compile $rootScope
$compile (dom,
$rootScope)
(function (window, document, undefined) {
'use strict';
// Functions declerations
jqLite(document).ready(function () {
angularInit(document, bootstrap);
});
})(window, document);
angularInit
bootstrap
doBootstrap
<html >
<body>
Hello {{'World'}}!
<script src="angular.js"></script>
<script>
angular.element(document).ready(function () {
angular.module('myApp', []);
angular.bootstrap(document, ['myApp']);
});
</script>
</body>
</html>
AngularJS Architecture
AngularJS Architecture
AngularJS Architecture
// Create a module
var myModule = angular.module('myModule', [])
// Configure the injector
myModule.factory('serviceA', function () {
return {
// instead of {}, put your object creation here
};
});
// create an injector and configure it from 'myModule'
var $injector = angular.injector(['myModule']);
// retrieve an object from the injector by name
var serviceA = $injector.get('serviceA');
// always true because of instance cache
$injector.get('serviceA') === $injector.get('serviceA');
// inferred (only works if code not minified/obfuscated)
$injector.invoke(function (serviceA) { });
// annotated
function explicit(serviceA) { };
explicit.$inject = ['serviceA'];
$injector.invoke(explicit);
// inline
$injector.invoke(['serviceA', function (serviceA) { }]);
// You write functions such as this one.
function doSomething(serviceA, serviceB) {
// do something here.
}
// Angular provides the injector for your application
var $injector = ...;
///////////////////////////////////////////////
// the old-school way of getting dependencies.
var serviceA = $injector.get('serviceA');
var serviceB = $injector.get('serviceB');
// now call the function
doSomething(serviceA, serviceB);
///////////////////////////////////////////////
// the cool way of getting dependencies.
$injector.invoke(doSomething)
$injector
Instance Cache
Provider Injector
instantiate
instantiate
Provider Cache
AngularJS Architecture
Config ( function( xxxProvider ){} )
Registration
- controller(name, constructor)
- directive(name, directiveFn)
- filter(name, filterFactory)
Registration ($provide)
- service(name, constructor)
- factory(name, providerFn)
- provider(name, providerType)
- decorator(name, fn )
- constant(name, object)
- value(name, object)
run(initializationFn)
Execute when the injector is done loading all modules.
ngXXX
angular.module('myApp', ['ngXXX', 'ngYYY']);
Constant
Provider
ngYYY
Constant
Providers
myApp
Constant
Providers
Config Config Config
Run Run Run
$injector
Instance
Cache
Provider
Cache
AngularJS Architecture
<div ng-controller="MyCtrl">
<ul>
<li ng-repeat="n in names">{{n}}</li>
</ul>
</div>
First the HTML is parsed into DOM
using the standard browser API.
Once all directives for a given
DOM element have been identified
they are sorted by priority and their
the directive compile() functions
are executed.
DOM + link($scope)
Live binding between the
scope and the DOM
Register any listeners on the
elements and set up any
watches with the scope.
var $compile = ...; // injected into your code
var scope = ...;
var html = '<div ng-bind="exp"></div>';
// Step 1: parse HTML into DOM element
var template = angular.element(html);
// Step 2: compile the template
var linkFn = $compile(template);
// Step 3: link the compiled template with the
scope.
linkFn(scope);
var myModule = angular.module(...);
myModule.directive('directiveName', function factory(injectables) {
var directiveDefinitionObject = {
priority: 0,
template: '<div></div>', // or function
templateUrl:'directive.html',
replace: false,
transclude: false,
restrict: 'A',
scope: false,
require: '^?ngModel'
controller: function($scope, $element, $attrs, $transclude, Injectables) { ... },
compile: function compile(tElement, tAttrs, transclude) {
return {
pre: function preLink(scope, iElement, iAttrs, controller) { ... },
post: function postLink(scope, iElement, iAttrs, controller) { ... }
}
},
link: function postLink(scope, iElement, iAttrs, controller) { ... }
};
return directiveDefinitionObject;
});
<div directive1 directive2>
<div directive3>
Hello World...
</div>
</div>
$compile start
$compile end
 Factory func
 Template
 Compile
 Controller
 preLink
 postLink
 Factory func
 Template
 Compile
 Controller
 preLink
 postLink
 Factory func
 Template
 Compile
 Controller
 preLink
 postLink
function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective,
previousCompileContext) {
...
var compositeLinkFn =
compileNodes( compileNodes, transcludeFn, $compileNodes,
maxPriority, ignoreDirective, previousCompileContext);
...
return function publicLinkFn(scope, cloneConnectFn, transcludeControllers) {
...
};
}
 Create all the DDO’s
 Execute all DDO’s template property or function
 Execute all DDO’s compile functions
 Execute all DDO’s controllers
 Execute all DDO’s preLink functions
 Execute all DDO’s postLink functions
function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority,
ignoreDirective, previousCompileContext) {
...
for (var i = 0; i < nodeList.length; i++) {
attrs = new Attributes();
directives = collectDirectives(nodeList[i], [], attrs,
i === 0 ? maxPriority : undefined, ignoreDirective);
nodeLinkFn = (directives.length)
? applyDirectivesToNode(directives, nodeList[i], attrs, ...)
: null;
...
childLinkFn = (nodeLinkFn ...) ? null : compileNodes( childNodes , ...);
...
}
...
}
 Scan the DOM (DFS) and find all directives
 Sort the directive by priority
 Execute the directive factory and store the DDO
 Call to the DDO.template
 Call to the DDO.compile
 Execute the compileNodes on the child nodes of
nodeList[i]
function bootstrap(element, modules) {
...
function(scope, element, compile, injector, animate) {
scope.$apply(function() {
element.data('$injector', injector);
compile(element)(scope);
});
...
}
<div directive1 directive2>
<div directive3>
Hello World...
</div>
</div>
$compile start
$compile end
 Factory func
 Template
 Compile
 Controller
 preLink
 postLink
 Factory func
 Template
 Compile
 Controller
 preLink
 postLink
 Factory func
 Template
 Compile
 Controller
 preLink
 postLink
AngularJS Architecture
 Factory func
 Template
 Compile
 Controller
 preLink
 postLink
<ul>
<li ng-repeat="x in [1,2,3,4]"
directive-name> {{x}} </li>
</ul>
var parseFn = $parse(' expression ');
var resultValue = parseFn($scope);
// Set value to expression
var setter = parseFn.assign;
setter(context,value);
Do in
compile
var temp = $interpolate( "{{a}}+{{b}}=<b>{{ result }}</b>" );
var result = temp( {a: '2', b: '3', result: '5'} );
Do in
compile $parse $parse $parse
$compile
$interpolate
$parse
<!-- Expressions -->
Please type your name : {{name}}
<!-- Directives & Data Binding -->
Name: <input ng-model="name" value="..." />
Template
name :
Scope
value
elm.bind('keydown', … )
$scope.$watch('name', … )
Directive
Native
Event
Queue
(wait)
DOM
Render
JavaScript
AngularJS
Event
Loop
$eval
Async
queue
$watch
list
// Pseudo-Code of $apply()
function $apply(expr) {
try {
return $eval(expr);
} catch (e) {
$exceptionHandler(e);
} finally {
$root.$digest();
}
}
...
var dereg = $scope.$watch('Model.Property', callbackOnChange());
…
// de-register $watch
dereg();
AngularJS Architecture
AngularJS Architecture
Counter = 0Counter = 1
scope.name = 'misko';
scope.counter = 0;
scope.$watch('name', function(newValue, oldValue)
{
scope.counter = scope.counter + 1;
});
scope.$digest();
scope.name = 'adam';
scope.$digest();
AngularJS Architecture
Root Scope
Scope
Scope Scope
AngularJS Architecture
Scope Type Properties:
 $id
Events:
 $destroy
Lifecycle Methods
 $destroy()
 $new(isolate)
Communication Methods:
 $broadcast(name, args)
 $emit(name, args)
 $on(name, listener)
Runtime Methods:
 $watch(…)
 $apply(exp)
 $digest()
 $eval(exp)
 $evalAsync(exp)
AngularJS Architecture

More Related Content

PDF
NestJS
Wilson Su
 
PPT
Nakov - .NET Framework Overview - English
Svetlin Nakov
 
PDF
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
 
PDF
Basics of JavaScript
Bala Narayanan
 
PPTX
Nodejs functions & modules
monikadeshmane
 
PPTX
Node js introduction
Joseph de Castelnau
 
PPTX
Angular Directives
Malla Reddy University
 
PPTX
Angular 2
Nigam Goyal
 
NestJS
Wilson Su
 
Nakov - .NET Framework Overview - English
Svetlin Nakov
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
 
Basics of JavaScript
Bala Narayanan
 
Nodejs functions & modules
monikadeshmane
 
Node js introduction
Joseph de Castelnau
 
Angular Directives
Malla Reddy University
 
Angular 2
Nigam Goyal
 

What's hot (20)

PPTX
Introduction Node.js
Erik van Appeldoorn
 
PPTX
Express JS
Alok Guha
 
PDF
Angular
Lilia Sfaxi
 
PDF
Nest.js Introduction
Takuya Tejima
 
DOCX
Angular Interview Questions & Answers
Ratnala Charan kumar
 
PDF
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Edureka!
 
PPTX
Angular interview questions
Goa App
 
PPTX
Namespaces in C#
yogita kachve
 
PPTX
Introduction to node.js
Dinesh U
 
PPTX
Typescript ppt
akhilsreyas
 
PPTX
Mongoose and MongoDB 101
Will Button
 
PDF
Solid NodeJS with TypeScript, Jest & NestJS
Rafael Casuso Romate
 
PPTX
Introducing type script
Remo Jansen
 
PDF
Data Persistence in Android with Room Library
Reinvently
 
PDF
Use Node.js to create a REST API
Fabien Vauchelles
 
PPT
Developing an ASP.NET Web Application
Rishi Kothari
 
PPT
Angular Introduction By Surekha Gadkari
Surekha Gadkari
 
PPT
Angular 8
Sunil OS
 
PDF
An introduction to React.js
Emanuele DelBono
 
PPT
Introduction To Dotnet
SAMIR BHOGAYTA
 
Introduction Node.js
Erik van Appeldoorn
 
Express JS
Alok Guha
 
Angular
Lilia Sfaxi
 
Nest.js Introduction
Takuya Tejima
 
Angular Interview Questions & Answers
Ratnala Charan kumar
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Edureka!
 
Angular interview questions
Goa App
 
Namespaces in C#
yogita kachve
 
Introduction to node.js
Dinesh U
 
Typescript ppt
akhilsreyas
 
Mongoose and MongoDB 101
Will Button
 
Solid NodeJS with TypeScript, Jest & NestJS
Rafael Casuso Romate
 
Introducing type script
Remo Jansen
 
Data Persistence in Android with Room Library
Reinvently
 
Use Node.js to create a REST API
Fabien Vauchelles
 
Developing an ASP.NET Web Application
Rishi Kothari
 
Angular Introduction By Surekha Gadkari
Surekha Gadkari
 
Angular 8
Sunil OS
 
An introduction to React.js
Emanuele DelBono
 
Introduction To Dotnet
SAMIR BHOGAYTA
 
Ad

Similar to AngularJS Architecture (20)

PPTX
AngularJS Compile Process
Eyal Vardi
 
PDF
Explaination of angular
Kan-Han (John) Lu
 
ODP
AngularJs Crash Course
Keith Bloomfield
 
PDF
Get AngularJS Started!
Dzmitry Ivashutsin
 
PPTX
AngularJS Directives
Eyal Vardi
 
PDF
"Inside The AngularJS Directive Compiler" by Tero Parviainen
Fwdays
 
PPTX
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
PPTX
Angular Deep Directive
Henry Tao
 
PPTX
Angular - Beginner
Riccardo Masetti
 
ODP
Angular js-crash-course
Keith Bloomfield
 
PDF
"Angular.js Concepts in Depth" by Aleksandar Simović
JS Belgrade
 
PDF
Workshop 14: AngularJS Parte III
Visual Engineering
 
PPTX
AngularJS
LearningTech
 
PPTX
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
PDF
AngularJS Basic Training
Cornel Stefanache
 
PDF
Angular custom directives
Alexe Bogdan
 
PDF
AngularJS Deep Dives (NYC GDG Apr 2013)
Nitya Narasimhan
 
PPTX
Front end development with Angular JS
Bipin
 
PPTX
angularJs Workshop
Ran Wahle
 
PPTX
Angular
LearningTech
 
AngularJS Compile Process
Eyal Vardi
 
Explaination of angular
Kan-Han (John) Lu
 
AngularJs Crash Course
Keith Bloomfield
 
Get AngularJS Started!
Dzmitry Ivashutsin
 
AngularJS Directives
Eyal Vardi
 
"Inside The AngularJS Directive Compiler" by Tero Parviainen
Fwdays
 
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
Angular Deep Directive
Henry Tao
 
Angular - Beginner
Riccardo Masetti
 
Angular js-crash-course
Keith Bloomfield
 
"Angular.js Concepts in Depth" by Aleksandar Simović
JS Belgrade
 
Workshop 14: AngularJS Parte III
Visual Engineering
 
AngularJS
LearningTech
 
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
AngularJS Basic Training
Cornel Stefanache
 
Angular custom directives
Alexe Bogdan
 
AngularJS Deep Dives (NYC GDG Apr 2013)
Nitya Narasimhan
 
Front end development with Angular JS
Bipin
 
angularJs Workshop
Ran Wahle
 
Angular
LearningTech
 
Ad

More from Eyal Vardi (20)

PPTX
Why magic
Eyal Vardi
 
PPTX
Smart Contract
Eyal Vardi
 
PDF
Rachel's grandmother's recipes
Eyal Vardi
 
PPTX
Performance Optimization In Angular 2
Eyal Vardi
 
PPTX
Angular 2 Architecture (Bucharest 26/10/2016)
Eyal Vardi
 
PPTX
Angular 2 NgModule
Eyal Vardi
 
PPTX
Upgrading from Angular 1.x to Angular 2.x
Eyal Vardi
 
PPTX
Angular 2 - Ahead of-time Compilation
Eyal Vardi
 
PPTX
Routing And Navigation
Eyal Vardi
 
PPTX
Angular 2 Architecture
Eyal Vardi
 
PPTX
Angular 1.x vs. Angular 2.x
Eyal Vardi
 
PPTX
Angular 2.0 Views
Eyal Vardi
 
PPTX
Component lifecycle hooks in Angular 2.0
Eyal Vardi
 
PPTX
Template syntax in Angular 2.0
Eyal Vardi
 
PPTX
Http Communication in Angular 2.0
Eyal Vardi
 
PPTX
Angular 2.0 Dependency injection
Eyal Vardi
 
PPTX
Angular 2.0 Routing and Navigation
Eyal Vardi
 
PPTX
Async & Parallel in JavaScript
Eyal Vardi
 
PPTX
Angular 2.0 Pipes
Eyal Vardi
 
PPTX
Angular 2.0 forms
Eyal Vardi
 
Why magic
Eyal Vardi
 
Smart Contract
Eyal Vardi
 
Rachel's grandmother's recipes
Eyal Vardi
 
Performance Optimization In Angular 2
Eyal Vardi
 
Angular 2 Architecture (Bucharest 26/10/2016)
Eyal Vardi
 
Angular 2 NgModule
Eyal Vardi
 
Upgrading from Angular 1.x to Angular 2.x
Eyal Vardi
 
Angular 2 - Ahead of-time Compilation
Eyal Vardi
 
Routing And Navigation
Eyal Vardi
 
Angular 2 Architecture
Eyal Vardi
 
Angular 1.x vs. Angular 2.x
Eyal Vardi
 
Angular 2.0 Views
Eyal Vardi
 
Component lifecycle hooks in Angular 2.0
Eyal Vardi
 
Template syntax in Angular 2.0
Eyal Vardi
 
Http Communication in Angular 2.0
Eyal Vardi
 
Angular 2.0 Dependency injection
Eyal Vardi
 
Angular 2.0 Routing and Navigation
Eyal Vardi
 
Async & Parallel in JavaScript
Eyal Vardi
 
Angular 2.0 Pipes
Eyal Vardi
 
Angular 2.0 forms
Eyal Vardi
 

Recently uploaded (20)

PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
This slide provides an overview Technology
mineshkharadi333
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 

AngularJS Architecture

  • 3. (function (window, document, undefined) { 'use strict'; // Functions declerations jqLite(document).ready(function () { angularInit(document, bootstrap); }); })(window, document); angularInit bootstrap doBootstrap
  • 4. <html > <body> Hello {{'World'}}! <script src="angular.js"></script> <script> angular.element(document).ready(function () { angular.module('myApp', []); angular.bootstrap(document, ['myApp']); }); </script> </body> </html>
  • 8. // Create a module var myModule = angular.module('myModule', []) // Configure the injector myModule.factory('serviceA', function () { return { // instead of {}, put your object creation here }; }); // create an injector and configure it from 'myModule' var $injector = angular.injector(['myModule']); // retrieve an object from the injector by name var serviceA = $injector.get('serviceA'); // always true because of instance cache $injector.get('serviceA') === $injector.get('serviceA');
  • 9. // inferred (only works if code not minified/obfuscated) $injector.invoke(function (serviceA) { }); // annotated function explicit(serviceA) { }; explicit.$inject = ['serviceA']; $injector.invoke(explicit); // inline $injector.invoke(['serviceA', function (serviceA) { }]);
  • 10. // You write functions such as this one. function doSomething(serviceA, serviceB) { // do something here. } // Angular provides the injector for your application var $injector = ...; /////////////////////////////////////////////// // the old-school way of getting dependencies. var serviceA = $injector.get('serviceA'); var serviceB = $injector.get('serviceB'); // now call the function doSomething(serviceA, serviceB); /////////////////////////////////////////////// // the cool way of getting dependencies. $injector.invoke(doSomething)
  • 13. Config ( function( xxxProvider ){} ) Registration - controller(name, constructor) - directive(name, directiveFn) - filter(name, filterFactory) Registration ($provide) - service(name, constructor) - factory(name, providerFn) - provider(name, providerType) - decorator(name, fn ) - constant(name, object) - value(name, object) run(initializationFn) Execute when the injector is done loading all modules.
  • 16. <div ng-controller="MyCtrl"> <ul> <li ng-repeat="n in names">{{n}}</li> </ul> </div> First the HTML is parsed into DOM using the standard browser API. Once all directives for a given DOM element have been identified they are sorted by priority and their the directive compile() functions are executed. DOM + link($scope) Live binding between the scope and the DOM Register any listeners on the elements and set up any watches with the scope. var $compile = ...; // injected into your code var scope = ...; var html = '<div ng-bind="exp"></div>'; // Step 1: parse HTML into DOM element var template = angular.element(html); // Step 2: compile the template var linkFn = $compile(template); // Step 3: link the compiled template with the scope. linkFn(scope);
  • 17. var myModule = angular.module(...); myModule.directive('directiveName', function factory(injectables) { var directiveDefinitionObject = { priority: 0, template: '<div></div>', // or function templateUrl:'directive.html', replace: false, transclude: false, restrict: 'A', scope: false, require: '^?ngModel' controller: function($scope, $element, $attrs, $transclude, Injectables) { ... }, compile: function compile(tElement, tAttrs, transclude) { return { pre: function preLink(scope, iElement, iAttrs, controller) { ... }, post: function postLink(scope, iElement, iAttrs, controller) { ... } } }, link: function postLink(scope, iElement, iAttrs, controller) { ... } }; return directiveDefinitionObject; });
  • 18. <div directive1 directive2> <div directive3> Hello World... </div> </div> $compile start $compile end  Factory func  Template  Compile  Controller  preLink  postLink  Factory func  Template  Compile  Controller  preLink  postLink  Factory func  Template  Compile  Controller  preLink  postLink
  • 19. function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext) { ... var compositeLinkFn = compileNodes( compileNodes, transcludeFn, $compileNodes, maxPriority, ignoreDirective, previousCompileContext); ... return function publicLinkFn(scope, cloneConnectFn, transcludeControllers) { ... }; }  Create all the DDO’s  Execute all DDO’s template property or function  Execute all DDO’s compile functions  Execute all DDO’s controllers  Execute all DDO’s preLink functions  Execute all DDO’s postLink functions
  • 20. function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective, previousCompileContext) { ... for (var i = 0; i < nodeList.length; i++) { attrs = new Attributes(); directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined, ignoreDirective); nodeLinkFn = (directives.length) ? applyDirectivesToNode(directives, nodeList[i], attrs, ...) : null; ... childLinkFn = (nodeLinkFn ...) ? null : compileNodes( childNodes , ...); ... } ... }  Scan the DOM (DFS) and find all directives  Sort the directive by priority  Execute the directive factory and store the DDO  Call to the DDO.template  Call to the DDO.compile  Execute the compileNodes on the child nodes of nodeList[i]
  • 21. function bootstrap(element, modules) { ... function(scope, element, compile, injector, animate) { scope.$apply(function() { element.data('$injector', injector); compile(element)(scope); }); ... } <div directive1 directive2> <div directive3> Hello World... </div> </div> $compile start $compile end  Factory func  Template  Compile  Controller  preLink  postLink  Factory func  Template  Compile  Controller  preLink  postLink  Factory func  Template  Compile  Controller  preLink  postLink
  • 23.  Factory func  Template  Compile  Controller  preLink  postLink <ul> <li ng-repeat="x in [1,2,3,4]" directive-name> {{x}} </li> </ul>
  • 24. var parseFn = $parse(' expression '); var resultValue = parseFn($scope); // Set value to expression var setter = parseFn.assign; setter(context,value); Do in compile
  • 25. var temp = $interpolate( "{{a}}+{{b}}=<b>{{ result }}</b>" ); var result = temp( {a: '2', b: '3', result: '5'} ); Do in compile $parse $parse $parse
  • 27. <!-- Expressions --> Please type your name : {{name}} <!-- Directives & Data Binding --> Name: <input ng-model="name" value="..." /> Template name : Scope value elm.bind('keydown', … ) $scope.$watch('name', … ) Directive
  • 29. // Pseudo-Code of $apply() function $apply(expr) { try { return $eval(expr); } catch (e) { $exceptionHandler(e); } finally { $root.$digest(); } }
  • 30. ... var dereg = $scope.$watch('Model.Property', callbackOnChange()); … // de-register $watch dereg();
  • 33. Counter = 0Counter = 1 scope.name = 'misko'; scope.counter = 0; scope.$watch('name', function(newValue, oldValue) { scope.counter = scope.counter + 1; }); scope.$digest(); scope.name = 'adam'; scope.$digest();
  • 37. Scope Type Properties:  $id Events:  $destroy Lifecycle Methods  $destroy()  $new(isolate) Communication Methods:  $broadcast(name, args)  $emit(name, args)  $on(name, listener) Runtime Methods:  $watch(…)  $apply(exp)  $digest()  $eval(exp)  $evalAsync(exp)