SlideShare ist ein Scribd-Unternehmen logo
1 von 21
(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

Weitere ähnliche Inhalte

Was ist angesagt? (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
 

Andere mochten auch

Angular custom directives
Angular custom directivesAngular custom directives
Angular custom directivesAlexe Bogdan
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basicsRavindra K
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS introdizabl
 
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 startedStéphane Bégaudeau
 

Andere mochten auch (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
 

Ähnlich wie Dependency Injection pattern in Angular

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.0Frost
 
"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 WorkshopRan Wahle
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project ReportKodexhub
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JSBipin
 
Services Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJSServices Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJSSumanth krishna
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014Ran 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 presentationMatus Szabo
 
Workshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIWorkshop 13: AngularJS Parte II
Workshop 13: AngularJS Parte IIVisual Engineering
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular jsAayush Shrestha
 
Leveling up with AngularJS
Leveling up with AngularJSLeveling up with AngularJS
Leveling up with AngularJSAustin Condiff
 

Ähnlich wie 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
 

Mehr von Alexe Bogdan

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

Mehr von 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?
 

Kürzlich hochgeladen

Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableSeo
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...tanu pandey
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...nilamkumrai
 
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLimonikaupta
 
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 Dubaikojalkojal131
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...SUHANI PANDEY
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
 
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...Delhi Call girls
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...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
 
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 👌 ⏭️ 6378878445ruhi
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...SUHANI PANDEY
 
Enjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...tanu pandey
 

Kürzlich hochgeladen (20)

(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
 
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
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
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
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...
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
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...
 
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
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
Enjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Samalka Delhi >༒8448380779 Escort Service
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 

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