SlideShare una empresa de Scribd logo
1 de 21
angular
Modules (private)
angular.module( 'moduleName' , [ ] ) angular.module( 'moduleName' )
moduleName
<html lang="en" ng-app="myTodo">
<body>
...
<script src="lib/angular.js"></script>
<!-- My Modules -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
</body>
</html>
// app.js file must to be first
angular.module('myTodo',[]);
// controllers.js must to be after app.js
angular.module('myTodo');
angular.module('myApp', ['bl'])
// Name (key) and value (function)
.controller('MainCtrl',MainCtrl)
.directive ('tabs',tabsDirective)
.provider('proxy',proxyProvider)
// Functions only
.config(function(proxyProvider){…})
.run(function(proxy){…});
 name : 'myApp'
 requires : [ 'bl']
_runBlocks : [ ]
_configBlocks : [ ]
_invokeQueue : [ ]
'MainCtrl',MainCtrl
'tabs',tabsDirective
'proxy',proxyProvider
function(proxyProvider){…}
function(proxy){…}
 name : string
 requires : [ ]
_runBlocks : [ ]
run( initializationFn )
_configBlocks : [ ]
Config(function( xxxProvider ){ })
_invokeQueue : [ ]
- controller(name, constructor)
- directive (name, directiveFn)
- filter (name, filterFactory)
- animation (name, animationFactory)
- service (name, constructor)
- factory (name, providerFn)
- provider (name, providerType)
- decorator(name, fn )
- constant (name, object)
- value (name, object)
angular
Modules (private)
Browser
<html lang="en" ng-app="app">
<body>
<div class="view-container">
<div ng-view class="view-frame"></div>
</div>
<script src="lib/angular.js"></script>
<!-- Angular Modules -->
<script src="lib/angular-route.js"></script>
<!-- My Modules -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
</body>
</html>
ngRoute app
ctrls services
DOM Content
Loaded Event
var injector = createInjector(modules);
injector.invoke([
'$rootScope','$rootElement','$compile','$injector','$animate',
function(scope, element, compile, injector, animate) {
scope.$apply(function() {
element.data('$injector', injector);
compile(element)(scope);
});
}]
);
Create the injector and
load the modules to
the injector.
Compile the root
element and return
link function.
Execute the link
function with the root
scope.
Apply,
update
the page
angular
Modules (private)
ngRoute app
ctrls services
$injector (Instance Injector)
Provider Injector
Instance Cache
Provider Cache
Keys Values
Invoke( )get( )
Keys Values
instantiate( ) has( )
Invoke( )get( ) instantiate( ) has( )
angular
Modules (private)
ngRoute
app
ctrls
services
<!-- app.js -->
angular.module('app',['ngRoute','ctrls'])
.config(function($routeProvider){});
<!-- angular-route.js -->
angular.module('ngRoute',[])
.provider('$route',fn);
<!-- controllers.js -->
angular.module('ctrls',['services'])
.controller('MainCtrl', fn);
<!-- services.js -->
angular.module('services',[])
.service('todoSer', fn);
<html lang="en" ng-app="app">
angular
Modules (private)
ngRoute
app
services
Provider Injector
Keys Values
todoSer
{ $get : factoryFn }
$controllerProvider
Keys Values
constructor
$route
{ $get : factoryFn }
config
ctrls
MainCtrl
{ $get : factoryFn }
todoSer
Provider
$route
Provider
angular
$injector
Provider Injector
Instance Cache
Provider Cache
Keys Values
{ $get : factoryFn }
{ $get : factoryFn }
todoSerProvider
$routeProvider
Invoke( )get( )
Keys Values
instantiate( ) has( )
Invoke( )get( ) instantiate( ) has( )
angular
Provider Injector
Instance Cache
Provider Cache
Keys Values
{ $get : factoryFn }
{ $get : factoryFn }
todoSerProvider
$routeProvider
angular.module('app',['ngRoute','ctrls']
.run(function runFn(todoSer){ todoSer.load(); });
Invoke( runFn )get( 'todoSer' )
get( 'todoSer' + 'Provider' )
Keys Values
{ . . .}todoSer
ngXXX
angular.module('myApp', ['ngXXX', 'ngYYY']);
Invoke
Queue
ngYYY
Invoke
Queue
myApp
Invoke
Queue
Config
blocks
Config
blocks
Config
blocks
Run
blocks
Run
blocks
Run
blocks
$injector
Instance
Cache
Provider
Cache
// You write functions such as this one.
function doSomething(serviceA, serviceB) {
// do something here.
}
// Angular provides the injector for your application
var $injector = ...;
$injector.invoke(doSomething);
var serviceA = $injector.get('serviceA');
var serviceB = $injector.get('serviceB');
doSomething(serviceA, serviceB);
// inline option
$injector.invoke( [ 'serviceA', function (serviceA) { } ] );
$injector.invoke( function (serviceA) { } );
$injector.invoke( function ( sa ) { } );
minified
xxx.js
xxx.min.js
// annotated option
explicit.$inject = ['serviceA'];
function explicit(serviceA) { };
$injector.invoke(explicit);
<ANY ng-app="angular.Module" [ng-strict-di="boolean"]>
...
</ANY>
Useful for debugging info, will assist in
tracking down the root of these bugs.
<html lang="en" ng-app="app">
<body>
<script src="lib/angular.js"></script>
<script src="lib/angular-route.js"></script>
<script src="js/app.js"></script>
</body>
</html>
angular.module('app', ['ngRoute']);
The module file are
being downloaded
correctly
The module name
in the requires is
not misspelled
<html lang="en" ng-app="app">
<body ng-controller="Ctrl">
<script src="angular.js"></script>
<script src="angular-route.js"></script>
<script src="app.js"></script>
</body>
</html>
angular.module('app', ['ngRoute']).controller('Ctrl', function(){...});
The module, where
the provider /
controller is
defined, is loaded
to the injector
Spelled
correctly
HTML
Browser
Static
DOM
Dynamic
DOM
(View)
AngularJS
DOM
Content
Loaded
Event
ng-app=“module”
$injector
$compile $rootScope
$compile (dom,
$rootScope)

Más contenido relacionado

La actualidad más candente

Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
Wei Ru
 

La actualidad más candente (20)

Template syntax in Angular 2.0
Template syntax in Angular 2.0Template syntax in Angular 2.0
Template syntax in Angular 2.0
 
AngularJS $Provide Service
AngularJS $Provide ServiceAngularJS $Provide Service
AngularJS $Provide Service
 
Databinding and Performance-Tuning in Angular 2
Databinding and Performance-Tuning in Angular 2Databinding and Performance-Tuning in Angular 2
Databinding and Performance-Tuning in Angular 2
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile Process
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
 
Angular 2.0 Routing and Navigation
Angular 2.0 Routing and NavigationAngular 2.0 Routing and Navigation
Angular 2.0 Routing and Navigation
 
Angular 2 Architecture
Angular 2 ArchitectureAngular 2 Architecture
Angular 2 Architecture
 
AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.
 
Angular 2 NgModule
Angular 2 NgModuleAngular 2 NgModule
Angular 2 NgModule
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
Angular js routing options
Angular js routing optionsAngular js routing options
Angular js routing options
 
AngularJs
AngularJsAngularJs
AngularJs
 
AngularJS Framework
AngularJS FrameworkAngularJS Framework
AngularJS Framework
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS Application
 
AngularJS Services
AngularJS ServicesAngularJS Services
AngularJS Services
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
준비하세요 Angular js 2.0
준비하세요 Angular js 2.0준비하세요 Angular js 2.0
준비하세요 Angular js 2.0
 

Destacado

Making use of OpenStreetMap data with Python
Making use of OpenStreetMap data with PythonMaking use of OpenStreetMap data with Python
Making use of OpenStreetMap data with Python
Andrii Mishkovskyi
 

Destacado (17)

Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & Streams
 
Node.js Socket.IO
Node.js  Socket.IONode.js  Socket.IO
Node.js Socket.IO
 
Node js overview
Node js overviewNode js overview
Node js overview
 
Node.js Event Emitter
Node.js Event EmitterNode.js Event Emitter
Node.js Event Emitter
 
Async & Parallel in JavaScript
Async & Parallel in JavaScriptAsync & Parallel in JavaScript
Async & Parallel in JavaScript
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
 
Angular 2.0 Pipes
Angular 2.0 PipesAngular 2.0 Pipes
Angular 2.0 Pipes
 
Nodejs
NodejsNodejs
Nodejs
 
Node.js Spplication Scaling
Node.js Spplication ScalingNode.js Spplication Scaling
Node.js Spplication Scaling
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
 
Modules in ECMAScript 6.0
Modules in ECMAScript 6.0Modules in ECMAScript 6.0
Modules in ECMAScript 6.0
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
 
Making use of OpenStreetMap data with Python
Making use of OpenStreetMap data with PythonMaking use of OpenStreetMap data with Python
Making use of OpenStreetMap data with Python
 
Rachel's grandmother's recipes
Rachel's grandmother's recipesRachel's grandmother's recipes
Rachel's grandmother's recipes
 
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing EraECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
OpenStreetMap in 3D using Python
OpenStreetMap in 3D using PythonOpenStreetMap in 3D using Python
OpenStreetMap in 3D using Python
 

Similar a Modules and injector

Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Jeado Ko
 

Similar a Modules and injector (20)

"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ć
 
Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2
 
AngularJs
AngularJsAngularJs
AngularJs
 
Angular2 + rxjs
Angular2 + rxjsAngular2 + rxjs
Angular2 + rxjs
 
Opinionated AngularJS
Opinionated AngularJSOpinionated AngularJS
Opinionated AngularJS
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
Protractor framework architecture with example
Protractor framework architecture with exampleProtractor framework architecture with example
Protractor framework architecture with example
 
Technozaure - Angular2
Technozaure - Angular2Technozaure - Angular2
Technozaure - Angular2
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Angular2 - In Action
Angular2  - In ActionAngular2  - In Action
Angular2 - In Action
 
A Story about AngularJS modularization development
A Story about AngularJS modularization developmentA Story about AngularJS modularization development
A Story about AngularJS modularization development
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
 
We sport architecture_implementation
We sport architecture_implementationWe sport architecture_implementation
We sport architecture_implementation
 
Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1
 
ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2ChtiJUG - Introduction à Angular2
ChtiJUG - Introduction à Angular2
 
Top 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeTop 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers Make
 
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
 
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점 Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
 
Angular js
Angular jsAngular js
Angular js
 

Más de Eyal Vardi (8)

Why magic
Why magicWhy magic
Why magic
 
Smart Contract
Smart ContractSmart Contract
Smart Contract
 
Proxies in ECMAScript 6.0
Proxies in ECMAScript 6.0Proxies in ECMAScript 6.0
Proxies in ECMAScript 6.0
 
Iterators & Generators in ECMAScript 6.0
Iterators & Generators in ECMAScript 6.0Iterators & Generators in ECMAScript 6.0
Iterators & Generators in ECMAScript 6.0
 
Symbols in ECMAScript 6.0
Symbols in ECMAScript 6.0Symbols in ECMAScript 6.0
Symbols in ECMAScript 6.0
 
Objects & Classes in ECMAScript 6.0
Objects & Classes in ECMAScript 6.0Objects & Classes in ECMAScript 6.0
Objects & Classes in ECMAScript 6.0
 
Scope & Functions in ECMAScript 6.0
Scope & Functions in ECMAScript 6.0Scope & Functions in ECMAScript 6.0
Scope & Functions in ECMAScript 6.0
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 

Modules and injector

  • 1.
  • 2. angular Modules (private) angular.module( 'moduleName' , [ ] ) angular.module( 'moduleName' ) moduleName
  • 3. <html lang="en" ng-app="myTodo"> <body> ... <script src="lib/angular.js"></script> <!-- My Modules --> <script src="js/app.js"></script> <script src="js/controllers.js"></script> </body> </html> // app.js file must to be first angular.module('myTodo',[]); // controllers.js must to be after app.js angular.module('myTodo');
  • 4. angular.module('myApp', ['bl']) // Name (key) and value (function) .controller('MainCtrl',MainCtrl) .directive ('tabs',tabsDirective) .provider('proxy',proxyProvider) // Functions only .config(function(proxyProvider){…}) .run(function(proxy){…});  name : 'myApp'  requires : [ 'bl'] _runBlocks : [ ] _configBlocks : [ ] _invokeQueue : [ ] 'MainCtrl',MainCtrl 'tabs',tabsDirective 'proxy',proxyProvider function(proxyProvider){…} function(proxy){…}
  • 5.  name : string  requires : [ ] _runBlocks : [ ] run( initializationFn ) _configBlocks : [ ] Config(function( xxxProvider ){ }) _invokeQueue : [ ] - controller(name, constructor) - directive (name, directiveFn) - filter (name, filterFactory) - animation (name, animationFactory) - service (name, constructor) - factory (name, providerFn) - provider (name, providerType) - decorator(name, fn ) - constant (name, object) - value (name, object)
  • 6. angular Modules (private) Browser <html lang="en" ng-app="app"> <body> <div class="view-container"> <div ng-view class="view-frame"></div> </div> <script src="lib/angular.js"></script> <!-- Angular Modules --> <script src="lib/angular-route.js"></script> <!-- My Modules --> <script src="js/app.js"></script> <script src="js/controllers.js"></script> <script src="js/services.js"></script> </body> </html> ngRoute app ctrls services DOM Content Loaded Event
  • 7.
  • 8. var injector = createInjector(modules); injector.invoke([ '$rootScope','$rootElement','$compile','$injector','$animate', function(scope, element, compile, injector, animate) { scope.$apply(function() { element.data('$injector', injector); compile(element)(scope); }); }] ); Create the injector and load the modules to the injector. Compile the root element and return link function. Execute the link function with the root scope. Apply, update the page
  • 9. angular Modules (private) ngRoute app ctrls services $injector (Instance Injector) Provider Injector Instance Cache Provider Cache Keys Values Invoke( )get( ) Keys Values instantiate( ) has( ) Invoke( )get( ) instantiate( ) has( )
  • 10. angular Modules (private) ngRoute app ctrls services <!-- app.js --> angular.module('app',['ngRoute','ctrls']) .config(function($routeProvider){}); <!-- angular-route.js --> angular.module('ngRoute',[]) .provider('$route',fn); <!-- controllers.js --> angular.module('ctrls',['services']) .controller('MainCtrl', fn); <!-- services.js --> angular.module('services',[]) .service('todoSer', fn); <html lang="en" ng-app="app">
  • 11. angular Modules (private) ngRoute app services Provider Injector Keys Values todoSer { $get : factoryFn } $controllerProvider Keys Values constructor $route { $get : factoryFn } config ctrls MainCtrl { $get : factoryFn } todoSer Provider $route Provider
  • 12. angular $injector Provider Injector Instance Cache Provider Cache Keys Values { $get : factoryFn } { $get : factoryFn } todoSerProvider $routeProvider Invoke( )get( ) Keys Values instantiate( ) has( ) Invoke( )get( ) instantiate( ) has( )
  • 13. angular Provider Injector Instance Cache Provider Cache Keys Values { $get : factoryFn } { $get : factoryFn } todoSerProvider $routeProvider angular.module('app',['ngRoute','ctrls'] .run(function runFn(todoSer){ todoSer.load(); }); Invoke( runFn )get( 'todoSer' ) get( 'todoSer' + 'Provider' ) Keys Values { . . .}todoSer
  • 15. // You write functions such as this one. function doSomething(serviceA, serviceB) { // do something here. } // Angular provides the injector for your application var $injector = ...; $injector.invoke(doSomething); var serviceA = $injector.get('serviceA'); var serviceB = $injector.get('serviceB'); doSomething(serviceA, serviceB);
  • 16. // inline option $injector.invoke( [ 'serviceA', function (serviceA) { } ] ); $injector.invoke( function (serviceA) { } ); $injector.invoke( function ( sa ) { } ); minified xxx.js xxx.min.js // annotated option explicit.$inject = ['serviceA']; function explicit(serviceA) { }; $injector.invoke(explicit);
  • 17. <ANY ng-app="angular.Module" [ng-strict-di="boolean"]> ... </ANY> Useful for debugging info, will assist in tracking down the root of these bugs.
  • 18. <html lang="en" ng-app="app"> <body> <script src="lib/angular.js"></script> <script src="lib/angular-route.js"></script> <script src="js/app.js"></script> </body> </html> angular.module('app', ['ngRoute']); The module file are being downloaded correctly The module name in the requires is not misspelled
  • 19. <html lang="en" ng-app="app"> <body ng-controller="Ctrl"> <script src="angular.js"></script> <script src="angular-route.js"></script> <script src="app.js"></script> </body> </html> angular.module('app', ['ngRoute']).controller('Ctrl', function(){...}); The module, where the provider / controller is defined, is loaded to the injector Spelled correctly
  • 20.