SlideShare a Scribd company logo
(DI) is a software design pattern that 
deals with how components get hold of their dependencies. 
The Angular injector subsystem is in charge 
of creating components, their , 
and them to other components as requested.
Angular modules have the opportunity to configure 
themselves before the module actually bootstraps and 
starts to run. 
This phase is the only part 
of the Angular flow that can 
modify things before the 
app starts up. 
The only services that can 
be injected in this block 
are and ; 
Executed at begining of the 
application; 
Similar with the 
method in other 
programming languages; 
Any service can be injected 
here.
singleton objects that are instantiated only once per 
application; 
lazy-loaded (created only when necessary); 
provide a way to share data and behavior across 
controllers, directives, filters or other services; 
How to create a service? 
Build your own DI system 
.constant(); 
.value(); 
.service(); 
.factory(); 
.provider();
used for registering a constant service such as string, 
number, array, object or function; 
doesn't have the ability to use other services (have 
dependencies); 
angular 
.module('myApp', []) 
.constant('apiUrl', 'http://localhost:8080') 
.config(['apiUrl', function(apiUrl){ 
//apiUrl can be used here 
}]) 
.run(['$rootScope', function($rootScope){ 
//apiUrl can be used here 
}]);
used for registering a value service such as string, 
number, array, object or function; 
doesn't have the ability to use other services (have 
dependencies); 
angular 
.module('myApp', []) 
.value('objectValue', { 
foo: 'bar' 
}) 
.run(['$rootScope', 'objectValue', 
function($rootScope, objectValue){ 
$rootScope.foo = objectValue.foo; 
} 
]);
used for registering a 
service factory which will be 
to return the 
; 
ability to use other services 
(have dependencies); 
service initialization; 
delayed/lazy initialization. 
angular 
.module('myApp', []) 
.factory('myFactory', function(){ 
var data; //private variable 
return { 
fetchData: function(){ 
//business to populate data 
}, 
getData: function(){ 
return data; 
} 
} 
}) 
.run(['$rootScope', 'myFactory', 
function($rootScope, myFactory){ 
myFactory.fetchData(); 
$rootScope.data = myFactory.getData(); 
} 
]);
used for registering a 
service constructor which 
will be invoked 
with to create the 
; 
same as factory; 
angular 
.module('myApp', []) 
.service('myService', function(){ 
var data; //private variable 
this.fetchData= function(){ 
//business to populate data 
}; 
this.getData= function(){ 
return data; 
}; 
}); 
.factory('myService', function(){ 
var Service = function(){ 
var data; //private variable 
this.fetchData= function(){ 
//business to populate data 
}; 
this.getData= function(){ 
return data; 
}; 
}; 
return new Service(); 
});
, whose instance is responsible for 
' ' a ; 
can have additional methods that allow configuration 
of the provider or it's returning service; 
must have a : 
that returns the factory service; 
ability to use other services (have dependencies);
angular 
.module('myApp', []) 
.provider('myFactory', function(){ 
var configVar = 'value'; 
//The factory Service - can have any dependency 
this.$get = ['$http', function($http){ 
var data; //private variable 
return{ 
fetchData: function(){ 
//business to populate data 
}, 
getData: function(){ 
return data; 
} 
}; 
}]; 
//Config method 
this.config = function(config){ 
configVar = config; 
}; 
}) 
.config(['myFactoryProvider', function(myFactoryProvider){ 
myFactoryProvider.config('Overriden value'); 
}]) 
.run(['$rootScope', 'myFactory', 
function($rootScope, myFactory){ 
myFactory.fetchData(); 
$rootScope.data = myFactory.getData() 
} 
]);
Angular comes with several built-in services like: 
$http / $httpProvider; 
$compile / $compileProvider; 
many more. 
The is a convention to point that the service comes 
from the framework and it is not custom-made;
All the providers (services) are . 
That means that they are all ; 
A constant is a value that can be injected everywhere. 
The value of a constant can never be changed; 
A value is just a simple injectable value; 
A service is an injectable constructor; 
A factory is an injectable function; 
A provider is a configurable factory.
Example Link
module is a core Angular module for basic routing. 
The module provides the directive, in order to render 
the appropriate template. 
Any time the route is changed the directive will update it's 
content: 
if there is a template associated with the current route: 
link the controller (if specified) with the scope; 
link the new scope with the new template; 
remove the last view and clean the last scope; 
create a new scope - inherited from the parent;
To create routes on a specific module or app, 
exposes the . 
To add a specific route, has the 
method 
$routeProvider 
.when('path', { 
template: '', 
templateUrl: '', 
controller: '', 
controllerAs: '' 
//... 
}) 
.otherwise(routeConfigObj);
<html ng-app="myApp"> 
<head>...</head> 
<body> 
<header> 
<h1>My app</h1> 
<ul> 
<li><a href="#/">Home</a></li> 
<li><a href="#/about">About</a></li> 
</ul> 
</header> 
<div class="content"> 
<div ng-view></div> 
</div> 
</body> 
</html> 
angular 
.module('myApp', ['ngRoute']) 
.config(['$routeProvider', function($routeProvider){ 
$routeProvider 
.when('/', { 
template: '<h2>{{page}}</h2>', 
controller: ['$scope', function($scope){ 
$scope.page = 'home'; 
}] 
}) 
.when('/about', { 
template: '<h2>{{page}}</h2>', 
controller: ['$scope', function($scope){ 
$scope.page = 'about'; 
}] 
}) 
.otherwise({redirectTo: '/'}); 
}]); 
Plunker Example
Dependency Injection pattern in Angular

More Related Content

What's hot

Angular js
Angular jsAngular js
Angular js
Knoldus Inc.
 
Meetup angular http client
Meetup angular http clientMeetup angular http client
Meetup angular http client
Gaurav Madaan
 
The productive developer guide to Angular 2
The productive developer guide to Angular 2The productive developer guide to Angular 2
The productive developer guide to Angular 2
Maurice De Beijer [MVP]
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
Christoffer Noring
 
jsf2 Notes
jsf2 Notesjsf2 Notes
jsf2 Notes
Rajiv Gupta
 
Angular App Presentation
Angular App PresentationAngular App Presentation
Angular App Presentation
Elizabeth Long
 
Angular 2: core concepts
Angular 2: core conceptsAngular 2: core concepts
Angular 2: core concepts
Codemotion
 
Angular2
Angular2Angular2
Angular
AngularAngular
Angular 2 - a New Hope
Angular 2 - a New HopeAngular 2 - a New Hope
Angular 2 - a New Hope
Sami Suo-Heikki
 
Data Flow Patterns in Angular 2 - Sebastian Müller
Data Flow Patterns in Angular 2 -  Sebastian MüllerData Flow Patterns in Angular 2 -  Sebastian Müller
Data Flow Patterns in Angular 2 - Sebastian Müller
Sebastian Holstein
 
Angular routing
Angular routingAngular routing
Angular routing
Sultan Ahmed
 
AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)
Abhishek Anand
 
Angular 5
Angular 5Angular 5
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questions
Goa App
 
Introduction to Unit Tests and TDD
Introduction to Unit Tests and TDDIntroduction to Unit Tests and TDD
Introduction to Unit Tests and TDD
Betclic Everest Group Tech Team
 
AngularJS
AngularJSAngularJS
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
Gaurav Agrawal
 
Angular 4 Introduction Tutorial
Angular 4 Introduction TutorialAngular 4 Introduction Tutorial
Angular 4 Introduction Tutorial
Scott Lee
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
Betclic Everest Group Tech Team
 

What's hot (20)

Angular js
Angular jsAngular js
Angular js
 
Meetup angular http client
Meetup angular http clientMeetup angular http client
Meetup angular http client
 
The productive developer guide to Angular 2
The productive developer guide to Angular 2The productive developer guide to Angular 2
The productive developer guide to Angular 2
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
jsf2 Notes
jsf2 Notesjsf2 Notes
jsf2 Notes
 
Angular App Presentation
Angular App PresentationAngular App Presentation
Angular App Presentation
 
Angular 2: core concepts
Angular 2: core conceptsAngular 2: core concepts
Angular 2: core concepts
 
Angular2
Angular2Angular2
Angular2
 
Angular
AngularAngular
Angular
 
Angular 2 - a New Hope
Angular 2 - a New HopeAngular 2 - a New Hope
Angular 2 - a New Hope
 
Data Flow Patterns in Angular 2 - Sebastian Müller
Data Flow Patterns in Angular 2 -  Sebastian MüllerData Flow Patterns in Angular 2 -  Sebastian Müller
Data Flow Patterns in Angular 2 - Sebastian Müller
 
Angular routing
Angular routingAngular routing
Angular routing
 
AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)
 
Angular 5
Angular 5Angular 5
Angular 5
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questions
 
Introduction to Unit Tests and TDD
Introduction to Unit Tests and TDDIntroduction to Unit Tests and TDD
Introduction to Unit Tests and TDD
 
AngularJS
AngularJSAngularJS
AngularJS
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
Angular 4 Introduction Tutorial
Angular 4 Introduction TutorialAngular 4 Introduction Tutorial
Angular 4 Introduction Tutorial
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 

Viewers also liked

Angular custom directives
Angular custom directivesAngular custom directives
Angular custom directives
Alexe Bogdan
 
Ajs ppt
Ajs pptAjs ppt
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
Ravindra K
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS intro
dizabl
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
Manish Shekhawat
 

Viewers also liked (6)

Angular custom directives
Angular custom directivesAngular custom directives
Angular custom directives
 
Ajs ppt
Ajs pptAjs ppt
Ajs ppt
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS intro
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 

Similar to Dependency Injection pattern in Angular

17612235.ppt
17612235.ppt17612235.ppt
17612235.ppt
yovixi5669
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
Pratchaya Suputsopon
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
Aishura Aishu
 
What is your money doing?
What is your money doing?What is your money doing?
What is your money doing?
Alfonso Fernández
 
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Frost
 
"Angular.js Concepts in Depth" by Aleksandar Simović
"Angular.js Concepts in Depth" by Aleksandar Simović"Angular.js Concepts in Depth" by Aleksandar Simović
"Angular.js Concepts in Depth" by Aleksandar Simović
JS Belgrade
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
Ran Wahle
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
Keith Bloomfield
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project Report
Kodexhub
 
Angular In Depth
Angular In DepthAngular In Depth
Angular In Depth
Mindfire Solutions
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
Bipin
 
Services Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJSServices Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJS
Sumanth krishna
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...
Katy Slemon
 
Angular presentation
Angular presentationAngular presentation
Angular presentation
Matus Szabo
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
Visual Engineering
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
Aayush Shrestha
 
Leveling up with AngularJS
Leveling up with AngularJSLeveling up with AngularJS
Leveling up with AngularJS
Austin Condiff
 
Angular2
Angular2Angular2
Angular2
kunalkumar376
 
Angular 2 in-1
Angular 2 in-1 Angular 2 in-1
Angular 2 in-1
GlobalLogic Ukraine
 

Similar to Dependency Injection pattern in Angular (20)

17612235.ppt
17612235.ppt17612235.ppt
17612235.ppt
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
 
What is your money doing?
What is your money doing?What is your money doing?
What is your money doing?
 
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
 
"Angular.js Concepts in Depth" by Aleksandar Simović
"Angular.js Concepts in Depth" by Aleksandar Simović"Angular.js Concepts in Depth" by Aleksandar Simović
"Angular.js Concepts in Depth" by Aleksandar Simović
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project Report
 
Angular In Depth
Angular In DepthAngular In Depth
Angular In Depth
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
 
Services Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJSServices Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJS
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...Understanding router state in angular 7 passing data through angular router s...
Understanding router state in angular 7 passing data through angular router s...
 
Angular presentation
Angular presentationAngular presentation
Angular presentation
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte II
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
Leveling up with AngularJS
Leveling up with AngularJSLeveling up with AngularJS
Leveling up with AngularJS
 
Angular2
Angular2Angular2
Angular2
 
Angular 2 in-1
Angular 2 in-1 Angular 2 in-1
Angular 2 in-1
 

More from Alexe Bogdan

Angular promises and http
Angular promises and httpAngular promises and http
Angular promises and http
Alexe Bogdan
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
Alexe Bogdan
 
HTML & JavaScript Introduction
HTML & JavaScript IntroductionHTML & JavaScript Introduction
HTML & JavaScript Introduction
Alexe Bogdan
 
Angular server-side communication
Angular server-side communicationAngular server-side communication
Angular server-side communication
Alexe Bogdan
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced Routing
Alexe Bogdan
 
AngularJS - introduction & how it works?
AngularJS - introduction & how it works?AngularJS - introduction & how it works?
AngularJS - introduction & how it works?
Alexe Bogdan
 

More from Alexe Bogdan (6)

Angular promises and http
Angular promises and httpAngular promises and http
Angular promises and http
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
 
HTML & JavaScript Introduction
HTML & JavaScript IntroductionHTML & JavaScript Introduction
HTML & JavaScript Introduction
 
Angular server-side communication
Angular server-side communicationAngular server-side communication
Angular server-side communication
 
Angular Promises and Advanced Routing
Angular Promises and Advanced RoutingAngular Promises and Advanced Routing
Angular Promises and Advanced Routing
 
AngularJS - introduction & how it works?
AngularJS - introduction & how it works?AngularJS - introduction & how it works?
AngularJS - introduction & how it works?
 

Recently uploaded

Azure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdfAzure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdf
AanSulistiyo
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
wolfsoftcompanyco
 
7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
Danica Gill
 
Gen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needsGen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needs
Laura Szabó
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
ysasp1
 
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
bseovas
 
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
uehowe
 
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
ukwwuq
 
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
zoowe
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
Paul Walk
 
Explore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories SecretlyExplore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories Secretly
Trending Blogers
 
Design Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptxDesign Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptx
saathvikreddy2003
 
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
uehowe
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
Trish Parr
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
cuobya
 
Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!
Toptal Tech
 
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
cuobya
 
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
uehowe
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
xjq03c34
 
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
vmemo1
 

Recently uploaded (20)

Azure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdfAzure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdf
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
 
7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
 
Gen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needsGen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needs
 
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
成绩单ps(UST毕业证)圣托马斯大学毕业证成绩单快速办理
 
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
 
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
 
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
制作原版1:1(Monash毕业证)莫纳什大学毕业证成绩单办理假
 
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
 
Explore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories SecretlyExplore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories Secretly
 
Design Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptxDesign Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptx
 
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
 
Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!
 
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
 
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
办理毕业证(UPenn毕业证)宾夕法尼亚大学毕业证成绩单快速办理
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
 
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
 

Dependency Injection pattern in Angular

  • 1.
  • 2.
  • 3.
  • 4.
  • 5. (DI) is a software design pattern that deals with how components get hold of their dependencies. The Angular injector subsystem is in charge of creating components, their , and them to other components as requested.
  • 6. Angular modules have the opportunity to configure themselves before the module actually bootstraps and starts to run. This phase is the only part of the Angular flow that can modify things before the app starts up. The only services that can be injected in this block are and ; Executed at begining of the application; Similar with the method in other programming languages; Any service can be injected here.
  • 7. singleton objects that are instantiated only once per application; lazy-loaded (created only when necessary); provide a way to share data and behavior across controllers, directives, filters or other services; How to create a service? Build your own DI system .constant(); .value(); .service(); .factory(); .provider();
  • 8. used for registering a constant service such as string, number, array, object or function; doesn't have the ability to use other services (have dependencies); angular .module('myApp', []) .constant('apiUrl', 'http://localhost:8080') .config(['apiUrl', function(apiUrl){ //apiUrl can be used here }]) .run(['$rootScope', function($rootScope){ //apiUrl can be used here }]);
  • 9. used for registering a value service such as string, number, array, object or function; doesn't have the ability to use other services (have dependencies); angular .module('myApp', []) .value('objectValue', { foo: 'bar' }) .run(['$rootScope', 'objectValue', function($rootScope, objectValue){ $rootScope.foo = objectValue.foo; } ]);
  • 10. used for registering a service factory which will be to return the ; ability to use other services (have dependencies); service initialization; delayed/lazy initialization. angular .module('myApp', []) .factory('myFactory', function(){ var data; //private variable return { fetchData: function(){ //business to populate data }, getData: function(){ return data; } } }) .run(['$rootScope', 'myFactory', function($rootScope, myFactory){ myFactory.fetchData(); $rootScope.data = myFactory.getData(); } ]);
  • 11. used for registering a service constructor which will be invoked with to create the ; same as factory; angular .module('myApp', []) .service('myService', function(){ var data; //private variable this.fetchData= function(){ //business to populate data }; this.getData= function(){ return data; }; }); .factory('myService', function(){ var Service = function(){ var data; //private variable this.fetchData= function(){ //business to populate data }; this.getData= function(){ return data; }; }; return new Service(); });
  • 12. , whose instance is responsible for ' ' a ; can have additional methods that allow configuration of the provider or it's returning service; must have a : that returns the factory service; ability to use other services (have dependencies);
  • 13. angular .module('myApp', []) .provider('myFactory', function(){ var configVar = 'value'; //The factory Service - can have any dependency this.$get = ['$http', function($http){ var data; //private variable return{ fetchData: function(){ //business to populate data }, getData: function(){ return data; } }; }]; //Config method this.config = function(config){ configVar = config; }; }) .config(['myFactoryProvider', function(myFactoryProvider){ myFactoryProvider.config('Overriden value'); }]) .run(['$rootScope', 'myFactory', function($rootScope, myFactory){ myFactory.fetchData(); $rootScope.data = myFactory.getData() } ]);
  • 14. Angular comes with several built-in services like: $http / $httpProvider; $compile / $compileProvider; many more. The is a convention to point that the service comes from the framework and it is not custom-made;
  • 15. All the providers (services) are . That means that they are all ; A constant is a value that can be injected everywhere. The value of a constant can never be changed; A value is just a simple injectable value; A service is an injectable constructor; A factory is an injectable function; A provider is a configurable factory.
  • 17.
  • 18. module is a core Angular module for basic routing. The module provides the directive, in order to render the appropriate template. Any time the route is changed the directive will update it's content: if there is a template associated with the current route: link the controller (if specified) with the scope; link the new scope with the new template; remove the last view and clean the last scope; create a new scope - inherited from the parent;
  • 19. To create routes on a specific module or app, exposes the . To add a specific route, has the method $routeProvider .when('path', { template: '', templateUrl: '', controller: '', controllerAs: '' //... }) .otherwise(routeConfigObj);
  • 20. <html ng-app="myApp"> <head>...</head> <body> <header> <h1>My app</h1> <ul> <li><a href="#/">Home</a></li> <li><a href="#/about">About</a></li> </ul> </header> <div class="content"> <div ng-view></div> </div> </body> </html> angular .module('myApp', ['ngRoute']) .config(['$routeProvider', function($routeProvider){ $routeProvider .when('/', { template: '<h2>{{page}}</h2>', controller: ['$scope', function($scope){ $scope.page = 'home'; }] }) .when('/about', { template: '<h2>{{page}}</h2>', controller: ['$scope', function($scope){ $scope.page = 'about'; }] }) .otherwise({redirectTo: '/'}); }]); Plunker Example