SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
MODULES IN
ANGULAR2
@DRPICOX
MODULE =
MODULES IN NG1
INJECTIONS CONFIG RUN+ +
angular.module(‘…’, […])
angular.module(‘booksServices’,[])
.value(‘Book’, Book)
.service(‘booksService’, BookService)
.factory(‘booksDictionary’, booksDictionaryFactory)
.provider(‘booksRemote’, BooksRemoteProvider)
INJECTIONS
booksDictionaryFactory.$inject = [‘Book’];
function booksDictionaryFactory ( Book ) {
…
}
MODULES IN NG1
$injector
{
‘Book’: Book,
}
INJECTIONS
angular.module(‘booksServices’,[])
.value(‘Book’, Book)
.service(‘booksService’, BookService)
.factory(‘booksDictionary’, booksDictionaryFactory)
.provider(‘booksRemote’, BooksRemoteProvider)
LibraryService.$inject = [‘booksService’];
function LibraryService ( booksService ) {
…
}
MODULES IN NG1
$injector
{
‘Book’: Book,
‘booksService’: new BooksService(),
}
INJECTIONS
angular.module(‘booksServices’,[])
.value(‘Book’, Book)
.service(‘booksService’, BookService)
.factory(‘booksDictionary’, booksDictionaryFactory)
.provider(‘booksRemote’, BooksRemoteProvider)
MODULES IN NG1
$injector
{
‘Book’: Book,
‘booksService’: new BooksService(),
‘booksDictionary’: booksDictionaryFactory(),
}
BooksService.$inject = [‘booksDictionary’,’booksRemote’];
function BooksService ( booksDictionary , booksRemote ) {
…
}
INJECTIONS
angular.module(‘booksServices’,[])
.value(‘Book’, Book)
.service(‘booksService’, BookService)
.factory(‘booksDictionary’, booksDictionaryFactory)
.provider(‘booksRemote’, BooksRemoteProvider)
MODULES IN NG1
$injector
{
‘Book’: Book,
‘booksService’: new BooksService(),
‘booksDictionary’: booksDictionaryFactory(),
‘booksRemote’: new BooksRemoteProvider().$get(),
}
BooksService.$inject = [‘booksDictionary’,’booksRemote’];
function BooksService ( booksDictionary , booksRemote ) {
…
}
INJECTIONS
angular.module(‘booksServices’,[])
.value(‘Book’, Book)
.service(‘booksService’, BookService)
.factory(‘booksDictionary’, booksDictionaryFactory)
.provider(‘booksRemote’, BooksRemoteProvider)
{
‘Book’: Book,
‘booksService’: new BooksService(),
‘booksDictionary’: booksDictionaryFactory(),
‘booksRemote’: new BooksRemoteProvider().$get(),
}
MODULES IN NG1
$injector
Catalog from injections how to create instances
A dictionary of instances already created to be reused
MODULES IN NG1
angular.module(‘booksStoreApp’, [
‘booksServices’, ‘booksComponents’
])
angular.module(‘booksServices’,[])
MODULES IN NG1
booksServices
injections
booksS
erv…
angular.module(‘bookStoreApp’, [
‘booksServices’, ‘booksComponents’
]);
booksS
erv…
angular.module(‘booksComponents’,[])
booksComponents
injections
booksC
omp…
booksC
omp…
+
=
angular.module(‘bookStoreApp’,[‘booksServices’,’booksComponents’])
booksServices
injections
booksC
omp…
booksS
erv…
booksComponents
injections
booksS
erv…
booksC
omp…
MODULES IN NG1
In Angular1 there is only one injector.
booksServices
injections
booksComponents
injections
$injector
MODULES IN NG1
In Angular1 there is only one injector.
That shares instances among all angular application.
(any “artifact” may demand any instance, no limits, aware with name aliasing)
booksServices
injections
booksComponents
injections
$injector
ng
injections
ngSanitize
injections
ngAria
injections
ngAnimate
injections
ngCookies
injections
ngTouch
injections
ngCordova
injections
mgcrea.ngStrap
injections
ui.router
injections
ngFileUpload
injections
{
‘booksService’: new BooksService(),
…
}
¿WHAT
ABOUT
ANGULAR2?
NG2
THERE ARE NO MODULES
MODULES IN NG2
MODULES IN NG2
THERE ARE NO MODULES
// boot.js
'use strict';
var bootstrap = require('angular2/platform/browser').bootstrap;
var BookStoreComponent = require(‘./bookstore').BookStoreComponent;
var BOOKSTORE_PROVIDERS = require(‘./bookstore').BOOKSTORE_PROVIDERS;
exports = boot;
function boot() {
bootstrap(BookStoreComponent,[BOOKSTORE_PROVIDERS]);
}
What is BOOKSTORE_PROVIDERS?
MODULES IN NG2
THERE ARE NO MODULES
// bookstore/index.js
'use strict';
var BOOKS_COMPONENTS_PROVIDERS =
require(‘./books-components’).BOOKS_COMPONENTS_PROVIDERS;
var BOOKS_SERVICES_PROVIDERS =
require(‘./books-services’).BOOKS_SERVICES_PROVIDERS;
exports.BookStoreComponent = require(‘./BookStoreComponent’);
exports.BOOKSTORE_PROVIDERS = [
BOOKS_COMPONENTS_PROVIDERS,
BOOKS_SERVICES_PROVIDERS,
];
BOOKSTORE_PROVIDERS is an array with more providers.
What are BOOKS_SERVICES_PROVIDERS, BOOKS_COMPONENTS_PROVIDERS?
MODULES IN NG2
THERE ARE NO MODULES
// bookstore/books-services/index.js
'use strict';
var Book = require(‘./Book’);
var BooksService = require(‘./BooksService’);
var booksDictionaryFactory = require(‘./booksDictionaryFactory’);
var BooksRemoteProvider = require(‘./BooksRemoteProvider’);
// ^^^ extends Provider ???
X
MODULES IN NG2
THERE ARE NO MODULES
// bookstore/books-services/index.js
…
exports.Book = Book;
exports.BooksService = BooksService;
var BooksDictionary = {}; // a dummy to have a symbol for injection ???
exports.BooksDictionary = BooksDictionary; // do not export factory
export.BooksRemoteProvider = BooksRemoteProvider;
export.BooksRemote = BooksRemoteProvider.BooksRemote; // ???
…
X
MODULES IN NG2
THERE ARE NO MODULES
// bookstore/books-services/index.js
…
var provide = require(‘angular2/core’).provide;
var HTTP_PROVIDERS = require(‘angular2/http').HTTP_PROVIDERS;
exports.BOOKS_SERVICES_PROVIDERS = [
HTTP_PROVIDERS,
provide(Book, {useValue: Book}),
BooksService, // === provide(BooksService, {useClass: BooksService})
provide(BooksDictionary, {useFactory: booksDictionaryFactory}),
BooksRemoteProvider,
];
X
MODULES IN NG2
THERE ARE NO MODULES
What I did wrong?
X
EASY TO GO RECIPE
MODULES IN NG2
EASY TO GO RECIPE
MODULES NG2
• Do not add value classes to PROVIDERS (like Book),

you may use export/import/require

(like components)
• Have only Services (provide(Class, {useClass: ClassName}))

(and use short form)
So… only use PROVIDERS for such things that you need a singleton.
Rule of thumb: do not define providers for classes in which have many “new”
(like Book, or like Components)
MODULES IN NG2
EASY TO GO RECIPE
// bookstore/books-services/index.js
'use strict';
var BooksService = require(‘./BooksService’);
var BooksDictionary = require(‘./BooksDictionary’);
var BooksRemote = require(‘./BooksRemote’);
exports.Book = Book;
exports.BooksService = BooksService;
exports.BooksDictionary = BooksDictionary;
exports.BooksRemote = BooksRemote;
var HTTP_PROVIDERS = require(‘angular2/http').HTTP_PROVIDERS;
exports.BOOKS_SERVICES_PROVIDERS = [
HTTP_PROVIDERS,
BooksService, BooksDictionary, BooksRemoteProvider,
];
Much better!
MODULES IN NG2
EASY TO GO RECIPE WITH COMPONENTS
// bookstore/books-services/index.js
'use strict';
exports.BookEditorComponent = require(‘./BookEditorComponent’);
exports.BookViewerComponent = require(‘./BookViewerComponent’);
exports.BooksListComponent = require(‘./BooksListComponent’);
// it requires books providers
var BOOKS_SERVICES_PROVIDERS =
require(‘../books-services’).BOOKS_SERVICES_PROVIDERS;
exports.BOOKS_COMPONENTS_PROVIDERS = [
BOOKS_SERVICES_PROVIDERS,
];
Nothing happens if the same “provider” is included twice.
MODULES IN NG2
FINAL PROVIDERS
Nothing happens if the same “provider” is included twice.
BOOKSTORE_PROVIDERS
===
[
BOOKS_COMPONENTS_PROVIDERS,
BOOKS_SERVICES_PROVIDERS,
];
MODULES IN NG2
FINAL PROVIDERS
Nothing happens if the same “provider” is included twice.
BOOKSTORE_PROVIDERS
===
[
BOOKS_COMPONENTS_PROVIDERS,
BOOKS_SERVICES_PROVIDERS,
];
BOOKS_COMPONENTS_PROVIDERS
===
[
BOOKS_COMPONENTS_PROVIDERS,
];
MODULES IN NG2
FINAL PROVIDERS
Nothing happens if the same “provider” is included twice.
BOOKSTORE_PROVIDERS
===
[
[
BOOKS_SERVICES_PROVIDERS
],
BOOKS_SERVICES_PROVIDERS,
];
BOOKS_COMPONENTS_PROVIDERS
===
[
BOOKS_COMPONENTS_PROVIDERS,
];
MODULES IN NG2
FINAL PROVIDERS
Nothing happens if the same “provider” is included twice.
BOOKSTORE_PROVIDERS
===
[
[
BOOKS_SERVICES_PROVIDERS
],
BOOKS_SERVICES_PROVIDERS,
];
BOOKS_SERVICES_PROVIDERS
===
[
HTTP_PROVIDERS,
BooksService,
BooksDictionary,
BooksRemoteProvider,
];
MODULES IN NG2
FINAL PROVIDERS
Nothing happens if the same “provider” is included twice.
BOOKSTORE_PROVIDERS
===
[
[
[
HTTP_PROVIDERS,
BooksService,
BooksDictionary,
BooksRemoteProvider,
]
],
[
HTTP_PROVIDERS,
BooksService,
BooksDictionary,
BooksRemoteProvider,
],
];
BOOKS_SERVICES_PROVIDERS
===
[
HTTP_PROVIDERS,
BooksService,
BooksDictionary,
BooksRemoteProvider,
];
MODULES IN NG2
FINAL PROVIDERS
Nothing happens if the same “provider” is included twice.
BOOKSTORE_PROVIDERS
===
[
[
[
HTTP_PROVIDERS,
BooksService,
BooksDictionary,
BooksRemoteProvider,
]
],
[
HTTP_PROVIDERS,
BooksService,
BooksDictionary,
BooksRemoteProvider,
],
];
HTTP_PROVIDERS
===
export const HTTP_PROVIDERS: any[] = [
// TODO(pascal): use factory type annotations once supported
// issue: https://github.com/angular/angular/issues/3183
provide(Http,
{
useFactory: (xhrBackend, requestOptions) =>
new Http(xhrBackend, requestOptions),
deps: [XHRBackend, RequestOptions]
}),
BrowserXhr,
provide(RequestOptions, {useClass: BaseRequestOptions}),
provide(ResponseOptions, {useClass: BaseResponseOptions}),
XHRBackend
];
https://github.com/angular/angular/blob/
2.0.0-beta.2/modules/angular2/http.ts#L154-L166
MODULES IN NG2
FINAL PROVIDERS
Nothing happens if the same “provider” is included twice.
BOOKSTORE_PROVIDERS
===
[
[
[
[…],
BooksService,
BooksDictionary,
BooksRemoteProvider,
]
],
[
[…],
BooksService,
BooksDictionary,
BooksRemoteProvider,
],
];
HTTP_PROVIDERS
===
export const HTTP_PROVIDERS: any[] = [
// TODO(pascal): use factory type annotations once supported
// issue: https://github.com/angular/angular/issues/3183
provide(Http,
{
useFactory: (xhrBackend, requestOptions) =>
new Http(xhrBackend, requestOptions),
deps: [XHRBackend, RequestOptions]
}),
BrowserXhr,
provide(RequestOptions, {useClass: BaseRequestOptions}),
provide(ResponseOptions, {useClass: BaseResponseOptions}),
XHRBackend
];
https://github.com/angular/angular/blob/
2.0.0-beta.2/modules/angular2/http.ts#L154-L166
SO… WHAT IS A “MODULE” IN ANGULAR2?
MODULES IN NG2
ANGULAR2 MODULES
MODULES NG2
• A module is a resource that exports:
• Components
• Classes
• And an array of PROVIDERS

(does not matter if we repeat things)
MODULES IN NG2
“MODULE” EXAMPLE 1
// bookstore/index.js
'use strict';
var BOOKS_COMPONENTS_PROVIDERS =
require(‘./books-components’).BOOKS_COMPONENTS_PROVIDERS;
var BOOKS_SERVICES_PROVIDERS =
require(‘./books-services’).BOOKS_SERVICES_PROVIDERS;
exports.BookStoreComponent = require(‘./BookStoreComponent’);
exports.BOOKSTORE_PROVIDERS = [
BOOKS_COMPONENTS_PROVIDERS,
BOOKS_SERVICES_PROVIDERS,
];
MODULES IN NG2
“MODULE” EXAMPLE 2
// bookstore/books-services/index.js
'use strict';
var BooksService = require(‘./BooksService’);
var BooksDictionary = require(‘./BooksDictionary’);
var BooksRemote = require(‘./BooksRemote’);
exports.Book = Book;
exports.BooksService = BooksService;
exports.BooksDictionary = BooksDictionary;
exports.BooksRemote = BooksRemote;
var HTTP_PROVIDERS = require(‘angular2/http').HTTP_PROVIDERS;
exports.BOOKS_SERVICES_PROVIDERS = [
HTTP_PROVIDERS,
BooksService, BooksDictionary, BooksRemoteProvider,
];
MODULES IN NG2
“MODULE” EXAMPLE 3
// bookstore/books-services/index.js
'use strict';
exports.BookEditorComponent = require(‘./BookEditorComponent’);
exports.BookViewerComponent = require(‘./BookViewerComponent’);
exports.BooksListComponent = require(‘./BooksListComponent’);
// it requires books providers
var BOOKS_SERVICES_PROVIDERS =
require(‘../books-services’).BOOKS_SERVICES_PROVIDERS;
exports.BOOKS_COMPONENTS_PROVIDERS = [
BOOKS_SERVICES_PROVIDERS,
];
ONE MORE THING…
MODULES IN NG2
ANGULAR 2 HAS MULTIPLE INJECTORS
MODULES IN NG2
ANGULAR 2 HAS UP TO ONE INJECTOR PER COMPONENT
MODULES IN NG2
ANGULAR 2 HAS MULTIPLE INJECTORS
MODULES NG2
ANGULAR 2 HAS MULTIPLE INJECTORS
MODULES NG2
• Angular2 has “almost” one injector per component
• There is a tree of injectors, if something is not found in your level,
it looks upper
• You can nest Angular2 apps (YEAH!)
• You can create providers for view models

(aka no more global model for toggle the state of the search bar)
MODULES IN NG2
ANGULAR 2 HAS MULTIPLE INJECTORS
import {Component, Input, Output, EventEmitter} from 'angular2/core';
import {RestoreService} from './restore.service';
import {Hero} from ‘./hero';
@Component({
selector: 'hero-editor',
providers: [RestoreService],
template: …
})
export class HeroEditorComponent {
…
}
https://angular.io/docs/ts/latest/guide/hierarchical-dependency-injection.html
DISCLAIMER
• I’m not an expert in Angular2, just a beginner
• I present it because I found very few example and nothing talking
about “modules”
• I want to share it so I can help others to save time
• Tests were done on Angular v2.0.0-beta.1, current is v2.0.0-beta.2,
but there is room for change

Contenu connexe

Tendances

Simpler Core Data with RubyMotion
Simpler Core Data with RubyMotionSimpler Core Data with RubyMotion
Simpler Core Data with RubyMotionStefan Haflidason
 
Jasig Rubyon Rails
Jasig Rubyon RailsJasig Rubyon Rails
Jasig Rubyon RailsPaul Pajo
 
Difference between java script and jquery
Difference between java script and jqueryDifference between java script and jquery
Difference between java script and jqueryUmar Ali
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy stepsprince Loffar
 
Intro to React
Intro to ReactIntro to React
Intro to ReactTroy Miles
 
jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling WebStackAcademy
 
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017Codemotion
 
[4developers] The saga pattern v3- Robert Pankowiecki
[4developers] The saga pattern v3- Robert Pankowiecki[4developers] The saga pattern v3- Robert Pankowiecki
[4developers] The saga pattern v3- Robert PankowieckiPROIDEA
 
Dart and AngularDart
Dart and AngularDartDart and AngularDart
Dart and AngularDartLoc Nguyen
 
Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...
Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...
Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...Jalal Mostafa
 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events WebStackAcademy
 
jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects  jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects WebStackAcademy
 
Single Page Applications Workshop Part II: Single Page Applications using Ang...
Single Page Applications Workshop Part II: Single Page Applications using Ang...Single Page Applications Workshop Part II: Single Page Applications using Ang...
Single Page Applications Workshop Part II: Single Page Applications using Ang...Jalal Mostafa
 
Introduction to Jquery
Introduction to Jquery Introduction to Jquery
Introduction to Jquery Tajendar Arora
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery BasicsKaloyan Kosev
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJSBrajesh Yadav
 

Tendances (20)

Simpler Core Data with RubyMotion
Simpler Core Data with RubyMotionSimpler Core Data with RubyMotion
Simpler Core Data with RubyMotion
 
Jasig Rubyon Rails
Jasig Rubyon RailsJasig Rubyon Rails
Jasig Rubyon Rails
 
Difference between java script and jquery
Difference between java script and jqueryDifference between java script and jquery
Difference between java script and jquery
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling
 
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
 
[4developers] The saga pattern v3- Robert Pankowiecki
[4developers] The saga pattern v3- Robert Pankowiecki[4developers] The saga pattern v3- Robert Pankowiecki
[4developers] The saga pattern v3- Robert Pankowiecki
 
Dart and AngularDart
Dart and AngularDartDart and AngularDart
Dart and AngularDart
 
Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...
Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...
Single Page Applications Workshop Part I: Interesting Topics in HTML5, CSS an...
 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events
 
jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects  jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects
 
jQuery
jQueryjQuery
jQuery
 
Single Page Applications Workshop Part II: Single Page Applications using Ang...
Single Page Applications Workshop Part II: Single Page Applications using Ang...Single Page Applications Workshop Part II: Single Page Applications using Ang...
Single Page Applications Workshop Part II: Single Page Applications using Ang...
 
Introduction to Jquery
Introduction to Jquery Introduction to Jquery
Introduction to Jquery
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
ParisJS #10 : RequireJS
ParisJS #10 : RequireJSParisJS #10 : RequireJS
ParisJS #10 : RequireJS
 
Underscore
UnderscoreUnderscore
Underscore
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJS
 

En vedette

Freelance i Enginyeria
Freelance i EnginyeriaFreelance i Enginyeria
Freelance i EnginyeriaDavid Rodenas
 
Angular 1.X Community and API Decissions
Angular 1.X Community and API DecissionsAngular 1.X Community and API Decissions
Angular 1.X Community and API DecissionsDavid Rodenas
 
Angular2 router&http
Angular2 router&httpAngular2 router&http
Angular2 router&httpDong Jun Kwon
 
Adventures with Angular 2
Adventures with Angular 2Adventures with Angular 2
Adventures with Angular 2Dragos Ionita
 
How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!Nir Kaufman
 
Angular2 - getting-ready
Angular2 - getting-ready Angular2 - getting-ready
Angular2 - getting-ready Nir Kaufman
 
Angular2 workshop
Angular2 workshopAngular2 workshop
Angular2 workshopNir Kaufman
 
Angular 2 - Core Concepts
Angular 2 - Core ConceptsAngular 2 - Core Concepts
Angular 2 - Core ConceptsFabio Biondi
 
RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015Ben Lesh
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2Knoldus Inc.
 
Getting Started with Angular 2
Getting Started with Angular 2Getting Started with Angular 2
Getting Started with Angular 2FITC
 
From high school to university and work
From high school to university and workFrom high school to university and work
From high school to university and workDavid Rodenas
 
Building Universal Applications with Angular 2
Building Universal Applications with Angular 2Building Universal Applications with Angular 2
Building Universal Applications with Angular 2Minko Gechev
 

En vedette (15)

Freelance i Enginyeria
Freelance i EnginyeriaFreelance i Enginyeria
Freelance i Enginyeria
 
Angular 1.X Community and API Decissions
Angular 1.X Community and API DecissionsAngular 1.X Community and API Decissions
Angular 1.X Community and API Decissions
 
Angular2 inter3
Angular2 inter3Angular2 inter3
Angular2 inter3
 
Angular2 router&http
Angular2 router&httpAngular2 router&http
Angular2 router&http
 
Adventures with Angular 2
Adventures with Angular 2Adventures with Angular 2
Adventures with Angular 2
 
Angular2
Angular2Angular2
Angular2
 
How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!How Angular2 Can Improve Your AngularJS Apps Today!
How Angular2 Can Improve Your AngularJS Apps Today!
 
Angular2 - getting-ready
Angular2 - getting-ready Angular2 - getting-ready
Angular2 - getting-ready
 
Angular2 workshop
Angular2 workshopAngular2 workshop
Angular2 workshop
 
Angular 2 - Core Concepts
Angular 2 - Core ConceptsAngular 2 - Core Concepts
Angular 2 - Core Concepts
 
RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Getting Started with Angular 2
Getting Started with Angular 2Getting Started with Angular 2
Getting Started with Angular 2
 
From high school to university and work
From high school to university and workFrom high school to university and work
From high school to university and work
 
Building Universal Applications with Angular 2
Building Universal Applications with Angular 2Building Universal Applications with Angular 2
Building Universal Applications with Angular 2
 

Similaire à Modules in angular 2.0 beta.1

A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...Corley S.r.l.
 
Performances & SEO in AngularJS
Performances & SEO in AngularJSPerformances & SEO in AngularJS
Performances & SEO in AngularJSPhilos.io
 
Arquitetando seu app Android com Jetpack
Arquitetando seu app Android com JetpackArquitetando seu app Android com Jetpack
Arquitetando seu app Android com JetpackNelson Glauber Leal
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-entechbed
 
Arquitetando seu app Android com Jetpack
Arquitetando seu app Android com JetpackArquitetando seu app Android com Jetpack
Arquitetando seu app Android com JetpackNelson Glauber Leal
 
Seu primeiro app Android e iOS com Compose Multiplatform
Seu primeiro app Android e iOS com Compose MultiplatformSeu primeiro app Android e iOS com Compose Multiplatform
Seu primeiro app Android e iOS com Compose MultiplatformNelson Glauber Leal
 

Similaire à Modules in angular 2.0 beta.1 (9)

A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...
 
Performances & SEO in AngularJS
Performances & SEO in AngularJSPerformances & SEO in AngularJS
Performances & SEO in AngularJS
 
Arquitetando seu app Android com Jetpack
Arquitetando seu app Android com JetpackArquitetando seu app Android com Jetpack
Arquitetando seu app Android com Jetpack
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-en
 
Rails vu d'un Javaiste
Rails vu d'un JavaisteRails vu d'un Javaiste
Rails vu d'un Javaiste
 
Arquitetando seu app Android com Jetpack
Arquitetando seu app Android com JetpackArquitetando seu app Android com Jetpack
Arquitetando seu app Android com Jetpack
 
AngularJs
AngularJsAngularJs
AngularJs
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
 
Seu primeiro app Android e iOS com Compose Multiplatform
Seu primeiro app Android e iOS com Compose MultiplatformSeu primeiro app Android e iOS com Compose Multiplatform
Seu primeiro app Android e iOS com Compose Multiplatform
 

Plus de David Rodenas

TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDDavid Rodenas
 
TDD CrashCourse Part1: Testing
TDD CrashCourse Part1: TestingTDD CrashCourse Part1: Testing
TDD CrashCourse Part1: TestingDavid Rodenas
 
TDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD TechniquesTDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD TechniquesDavid Rodenas
 
TDD CrashCourse Part5: Testing Techniques
TDD CrashCourse Part5: Testing TechniquesTDD CrashCourse Part5: Testing Techniques
TDD CrashCourse Part5: Testing TechniquesDavid Rodenas
 
TDD CrashCourse Part4: Improving Testing
TDD CrashCourse Part4: Improving TestingTDD CrashCourse Part4: Improving Testing
TDD CrashCourse Part4: Improving TestingDavid Rodenas
 
Be professional: We Rule the World
Be professional: We Rule the WorldBe professional: We Rule the World
Be professional: We Rule the WorldDavid Rodenas
 
ES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD CalculatorES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD CalculatorDavid Rodenas
 
ES3-2020-P2 Bowling Game Kata
ES3-2020-P2 Bowling Game KataES3-2020-P2 Bowling Game Kata
ES3-2020-P2 Bowling Game KataDavid Rodenas
 
ES3-2020-07 Testing techniques
ES3-2020-07 Testing techniquesES3-2020-07 Testing techniques
ES3-2020-07 Testing techniquesDavid Rodenas
 
ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)David Rodenas
 
Testing, Learning and Professionalism — 20171214
Testing, Learning and Professionalism — 20171214Testing, Learning and Professionalism — 20171214
Testing, Learning and Professionalism — 20171214David Rodenas
 
ReactJS for Programmers
ReactJS for ProgrammersReactJS for Programmers
ReactJS for ProgrammersDavid Rodenas
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS ProgrammersDavid Rodenas
 
Basic Tutorial of React for Programmers
Basic Tutorial of React for ProgrammersBasic Tutorial of React for Programmers
Basic Tutorial of React for ProgrammersDavid Rodenas
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxDavid Rodenas
 
(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and back(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and backDavid Rodenas
 

Plus de David Rodenas (20)

TDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDDTDD CrashCourse Part2: TDD
TDD CrashCourse Part2: TDD
 
TDD CrashCourse Part1: Testing
TDD CrashCourse Part1: TestingTDD CrashCourse Part1: Testing
TDD CrashCourse Part1: Testing
 
TDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD TechniquesTDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD Techniques
 
TDD CrashCourse Part5: Testing Techniques
TDD CrashCourse Part5: Testing TechniquesTDD CrashCourse Part5: Testing Techniques
TDD CrashCourse Part5: Testing Techniques
 
TDD CrashCourse Part4: Improving Testing
TDD CrashCourse Part4: Improving TestingTDD CrashCourse Part4: Improving Testing
TDD CrashCourse Part4: Improving Testing
 
Be professional: We Rule the World
Be professional: We Rule the WorldBe professional: We Rule the World
Be professional: We Rule the World
 
ES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD CalculatorES3-2020-P3 TDD Calculator
ES3-2020-P3 TDD Calculator
 
ES3-2020-P2 Bowling Game Kata
ES3-2020-P2 Bowling Game KataES3-2020-P2 Bowling Game Kata
ES3-2020-P2 Bowling Game Kata
 
ES3-2020-07 Testing techniques
ES3-2020-07 Testing techniquesES3-2020-07 Testing techniques
ES3-2020-07 Testing techniques
 
ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)
 
ES3-2020-05 Testing
ES3-2020-05 TestingES3-2020-05 Testing
ES3-2020-05 Testing
 
Testing, Learning and Professionalism — 20171214
Testing, Learning and Professionalism — 20171214Testing, Learning and Professionalism — 20171214
Testing, Learning and Professionalism — 20171214
 
ReactJS for Programmers
ReactJS for ProgrammersReactJS for Programmers
ReactJS for Programmers
 
Vespres
VespresVespres
Vespres
 
Faster web pages
Faster web pagesFaster web pages
Faster web pages
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS Programmers
 
Basic Tutorial of React for Programmers
Basic Tutorial of React for ProgrammersBasic Tutorial of React for Programmers
Basic Tutorial of React for Programmers
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicox
 
JS and patterns
JS and patternsJS and patterns
JS and patterns
 
(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and back(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and back
 

Dernier

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 

Dernier (20)

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 

Modules in angular 2.0 beta.1

  • 2. MODULE = MODULES IN NG1 INJECTIONS CONFIG RUN+ + angular.module(‘…’, […])
  • 3. angular.module(‘booksServices’,[]) .value(‘Book’, Book) .service(‘booksService’, BookService) .factory(‘booksDictionary’, booksDictionaryFactory) .provider(‘booksRemote’, BooksRemoteProvider) INJECTIONS booksDictionaryFactory.$inject = [‘Book’]; function booksDictionaryFactory ( Book ) { … } MODULES IN NG1 $injector { ‘Book’: Book, }
  • 4. INJECTIONS angular.module(‘booksServices’,[]) .value(‘Book’, Book) .service(‘booksService’, BookService) .factory(‘booksDictionary’, booksDictionaryFactory) .provider(‘booksRemote’, BooksRemoteProvider) LibraryService.$inject = [‘booksService’]; function LibraryService ( booksService ) { … } MODULES IN NG1 $injector { ‘Book’: Book, ‘booksService’: new BooksService(), }
  • 5. INJECTIONS angular.module(‘booksServices’,[]) .value(‘Book’, Book) .service(‘booksService’, BookService) .factory(‘booksDictionary’, booksDictionaryFactory) .provider(‘booksRemote’, BooksRemoteProvider) MODULES IN NG1 $injector { ‘Book’: Book, ‘booksService’: new BooksService(), ‘booksDictionary’: booksDictionaryFactory(), } BooksService.$inject = [‘booksDictionary’,’booksRemote’]; function BooksService ( booksDictionary , booksRemote ) { … }
  • 6. INJECTIONS angular.module(‘booksServices’,[]) .value(‘Book’, Book) .service(‘booksService’, BookService) .factory(‘booksDictionary’, booksDictionaryFactory) .provider(‘booksRemote’, BooksRemoteProvider) MODULES IN NG1 $injector { ‘Book’: Book, ‘booksService’: new BooksService(), ‘booksDictionary’: booksDictionaryFactory(), ‘booksRemote’: new BooksRemoteProvider().$get(), } BooksService.$inject = [‘booksDictionary’,’booksRemote’]; function BooksService ( booksDictionary , booksRemote ) { … }
  • 7. INJECTIONS angular.module(‘booksServices’,[]) .value(‘Book’, Book) .service(‘booksService’, BookService) .factory(‘booksDictionary’, booksDictionaryFactory) .provider(‘booksRemote’, BooksRemoteProvider) { ‘Book’: Book, ‘booksService’: new BooksService(), ‘booksDictionary’: booksDictionaryFactory(), ‘booksRemote’: new BooksRemoteProvider().$get(), } MODULES IN NG1 $injector Catalog from injections how to create instances A dictionary of instances already created to be reused
  • 8. MODULES IN NG1 angular.module(‘booksStoreApp’, [ ‘booksServices’, ‘booksComponents’ ])
  • 9. angular.module(‘booksServices’,[]) MODULES IN NG1 booksServices injections booksS erv… angular.module(‘bookStoreApp’, [ ‘booksServices’, ‘booksComponents’ ]); booksS erv… angular.module(‘booksComponents’,[]) booksComponents injections booksC omp… booksC omp… + = angular.module(‘bookStoreApp’,[‘booksServices’,’booksComponents’]) booksServices injections booksC omp… booksS erv… booksComponents injections booksS erv… booksC omp…
  • 10. MODULES IN NG1 In Angular1 there is only one injector. booksServices injections booksComponents injections $injector
  • 11. MODULES IN NG1 In Angular1 there is only one injector. That shares instances among all angular application. (any “artifact” may demand any instance, no limits, aware with name aliasing) booksServices injections booksComponents injections $injector ng injections ngSanitize injections ngAria injections ngAnimate injections ngCookies injections ngTouch injections ngCordova injections mgcrea.ngStrap injections ui.router injections ngFileUpload injections { ‘booksService’: new BooksService(), … }
  • 13. THERE ARE NO MODULES MODULES IN NG2
  • 14. MODULES IN NG2 THERE ARE NO MODULES // boot.js 'use strict'; var bootstrap = require('angular2/platform/browser').bootstrap; var BookStoreComponent = require(‘./bookstore').BookStoreComponent; var BOOKSTORE_PROVIDERS = require(‘./bookstore').BOOKSTORE_PROVIDERS; exports = boot; function boot() { bootstrap(BookStoreComponent,[BOOKSTORE_PROVIDERS]); } What is BOOKSTORE_PROVIDERS?
  • 15. MODULES IN NG2 THERE ARE NO MODULES // bookstore/index.js 'use strict'; var BOOKS_COMPONENTS_PROVIDERS = require(‘./books-components’).BOOKS_COMPONENTS_PROVIDERS; var BOOKS_SERVICES_PROVIDERS = require(‘./books-services’).BOOKS_SERVICES_PROVIDERS; exports.BookStoreComponent = require(‘./BookStoreComponent’); exports.BOOKSTORE_PROVIDERS = [ BOOKS_COMPONENTS_PROVIDERS, BOOKS_SERVICES_PROVIDERS, ]; BOOKSTORE_PROVIDERS is an array with more providers. What are BOOKS_SERVICES_PROVIDERS, BOOKS_COMPONENTS_PROVIDERS?
  • 16. MODULES IN NG2 THERE ARE NO MODULES // bookstore/books-services/index.js 'use strict'; var Book = require(‘./Book’); var BooksService = require(‘./BooksService’); var booksDictionaryFactory = require(‘./booksDictionaryFactory’); var BooksRemoteProvider = require(‘./BooksRemoteProvider’); // ^^^ extends Provider ??? X
  • 17. MODULES IN NG2 THERE ARE NO MODULES // bookstore/books-services/index.js … exports.Book = Book; exports.BooksService = BooksService; var BooksDictionary = {}; // a dummy to have a symbol for injection ??? exports.BooksDictionary = BooksDictionary; // do not export factory export.BooksRemoteProvider = BooksRemoteProvider; export.BooksRemote = BooksRemoteProvider.BooksRemote; // ??? … X
  • 18. MODULES IN NG2 THERE ARE NO MODULES // bookstore/books-services/index.js … var provide = require(‘angular2/core’).provide; var HTTP_PROVIDERS = require(‘angular2/http').HTTP_PROVIDERS; exports.BOOKS_SERVICES_PROVIDERS = [ HTTP_PROVIDERS, provide(Book, {useValue: Book}), BooksService, // === provide(BooksService, {useClass: BooksService}) provide(BooksDictionary, {useFactory: booksDictionaryFactory}), BooksRemoteProvider, ]; X
  • 19. MODULES IN NG2 THERE ARE NO MODULES What I did wrong? X
  • 20. EASY TO GO RECIPE MODULES IN NG2
  • 21. EASY TO GO RECIPE MODULES NG2 • Do not add value classes to PROVIDERS (like Book),
 you may use export/import/require
 (like components) • Have only Services (provide(Class, {useClass: ClassName}))
 (and use short form) So… only use PROVIDERS for such things that you need a singleton. Rule of thumb: do not define providers for classes in which have many “new” (like Book, or like Components)
  • 22. MODULES IN NG2 EASY TO GO RECIPE // bookstore/books-services/index.js 'use strict'; var BooksService = require(‘./BooksService’); var BooksDictionary = require(‘./BooksDictionary’); var BooksRemote = require(‘./BooksRemote’); exports.Book = Book; exports.BooksService = BooksService; exports.BooksDictionary = BooksDictionary; exports.BooksRemote = BooksRemote; var HTTP_PROVIDERS = require(‘angular2/http').HTTP_PROVIDERS; exports.BOOKS_SERVICES_PROVIDERS = [ HTTP_PROVIDERS, BooksService, BooksDictionary, BooksRemoteProvider, ]; Much better!
  • 23. MODULES IN NG2 EASY TO GO RECIPE WITH COMPONENTS // bookstore/books-services/index.js 'use strict'; exports.BookEditorComponent = require(‘./BookEditorComponent’); exports.BookViewerComponent = require(‘./BookViewerComponent’); exports.BooksListComponent = require(‘./BooksListComponent’); // it requires books providers var BOOKS_SERVICES_PROVIDERS = require(‘../books-services’).BOOKS_SERVICES_PROVIDERS; exports.BOOKS_COMPONENTS_PROVIDERS = [ BOOKS_SERVICES_PROVIDERS, ]; Nothing happens if the same “provider” is included twice.
  • 24. MODULES IN NG2 FINAL PROVIDERS Nothing happens if the same “provider” is included twice. BOOKSTORE_PROVIDERS === [ BOOKS_COMPONENTS_PROVIDERS, BOOKS_SERVICES_PROVIDERS, ];
  • 25. MODULES IN NG2 FINAL PROVIDERS Nothing happens if the same “provider” is included twice. BOOKSTORE_PROVIDERS === [ BOOKS_COMPONENTS_PROVIDERS, BOOKS_SERVICES_PROVIDERS, ]; BOOKS_COMPONENTS_PROVIDERS === [ BOOKS_COMPONENTS_PROVIDERS, ];
  • 26. MODULES IN NG2 FINAL PROVIDERS Nothing happens if the same “provider” is included twice. BOOKSTORE_PROVIDERS === [ [ BOOKS_SERVICES_PROVIDERS ], BOOKS_SERVICES_PROVIDERS, ]; BOOKS_COMPONENTS_PROVIDERS === [ BOOKS_COMPONENTS_PROVIDERS, ];
  • 27. MODULES IN NG2 FINAL PROVIDERS Nothing happens if the same “provider” is included twice. BOOKSTORE_PROVIDERS === [ [ BOOKS_SERVICES_PROVIDERS ], BOOKS_SERVICES_PROVIDERS, ]; BOOKS_SERVICES_PROVIDERS === [ HTTP_PROVIDERS, BooksService, BooksDictionary, BooksRemoteProvider, ];
  • 28. MODULES IN NG2 FINAL PROVIDERS Nothing happens if the same “provider” is included twice. BOOKSTORE_PROVIDERS === [ [ [ HTTP_PROVIDERS, BooksService, BooksDictionary, BooksRemoteProvider, ] ], [ HTTP_PROVIDERS, BooksService, BooksDictionary, BooksRemoteProvider, ], ]; BOOKS_SERVICES_PROVIDERS === [ HTTP_PROVIDERS, BooksService, BooksDictionary, BooksRemoteProvider, ];
  • 29. MODULES IN NG2 FINAL PROVIDERS Nothing happens if the same “provider” is included twice. BOOKSTORE_PROVIDERS === [ [ [ HTTP_PROVIDERS, BooksService, BooksDictionary, BooksRemoteProvider, ] ], [ HTTP_PROVIDERS, BooksService, BooksDictionary, BooksRemoteProvider, ], ]; HTTP_PROVIDERS === export const HTTP_PROVIDERS: any[] = [ // TODO(pascal): use factory type annotations once supported // issue: https://github.com/angular/angular/issues/3183 provide(Http, { useFactory: (xhrBackend, requestOptions) => new Http(xhrBackend, requestOptions), deps: [XHRBackend, RequestOptions] }), BrowserXhr, provide(RequestOptions, {useClass: BaseRequestOptions}), provide(ResponseOptions, {useClass: BaseResponseOptions}), XHRBackend ]; https://github.com/angular/angular/blob/ 2.0.0-beta.2/modules/angular2/http.ts#L154-L166
  • 30. MODULES IN NG2 FINAL PROVIDERS Nothing happens if the same “provider” is included twice. BOOKSTORE_PROVIDERS === [ [ [ […], BooksService, BooksDictionary, BooksRemoteProvider, ] ], [ […], BooksService, BooksDictionary, BooksRemoteProvider, ], ]; HTTP_PROVIDERS === export const HTTP_PROVIDERS: any[] = [ // TODO(pascal): use factory type annotations once supported // issue: https://github.com/angular/angular/issues/3183 provide(Http, { useFactory: (xhrBackend, requestOptions) => new Http(xhrBackend, requestOptions), deps: [XHRBackend, RequestOptions] }), BrowserXhr, provide(RequestOptions, {useClass: BaseRequestOptions}), provide(ResponseOptions, {useClass: BaseResponseOptions}), XHRBackend ]; https://github.com/angular/angular/blob/ 2.0.0-beta.2/modules/angular2/http.ts#L154-L166
  • 31. SO… WHAT IS A “MODULE” IN ANGULAR2? MODULES IN NG2
  • 32. ANGULAR2 MODULES MODULES NG2 • A module is a resource that exports: • Components • Classes • And an array of PROVIDERS
 (does not matter if we repeat things)
  • 33. MODULES IN NG2 “MODULE” EXAMPLE 1 // bookstore/index.js 'use strict'; var BOOKS_COMPONENTS_PROVIDERS = require(‘./books-components’).BOOKS_COMPONENTS_PROVIDERS; var BOOKS_SERVICES_PROVIDERS = require(‘./books-services’).BOOKS_SERVICES_PROVIDERS; exports.BookStoreComponent = require(‘./BookStoreComponent’); exports.BOOKSTORE_PROVIDERS = [ BOOKS_COMPONENTS_PROVIDERS, BOOKS_SERVICES_PROVIDERS, ];
  • 34. MODULES IN NG2 “MODULE” EXAMPLE 2 // bookstore/books-services/index.js 'use strict'; var BooksService = require(‘./BooksService’); var BooksDictionary = require(‘./BooksDictionary’); var BooksRemote = require(‘./BooksRemote’); exports.Book = Book; exports.BooksService = BooksService; exports.BooksDictionary = BooksDictionary; exports.BooksRemote = BooksRemote; var HTTP_PROVIDERS = require(‘angular2/http').HTTP_PROVIDERS; exports.BOOKS_SERVICES_PROVIDERS = [ HTTP_PROVIDERS, BooksService, BooksDictionary, BooksRemoteProvider, ];
  • 35. MODULES IN NG2 “MODULE” EXAMPLE 3 // bookstore/books-services/index.js 'use strict'; exports.BookEditorComponent = require(‘./BookEditorComponent’); exports.BookViewerComponent = require(‘./BookViewerComponent’); exports.BooksListComponent = require(‘./BooksListComponent’); // it requires books providers var BOOKS_SERVICES_PROVIDERS = require(‘../books-services’).BOOKS_SERVICES_PROVIDERS; exports.BOOKS_COMPONENTS_PROVIDERS = [ BOOKS_SERVICES_PROVIDERS, ];
  • 37. ANGULAR 2 HAS MULTIPLE INJECTORS MODULES IN NG2
  • 38. ANGULAR 2 HAS UP TO ONE INJECTOR PER COMPONENT MODULES IN NG2
  • 39. ANGULAR 2 HAS MULTIPLE INJECTORS MODULES NG2
  • 40. ANGULAR 2 HAS MULTIPLE INJECTORS MODULES NG2 • Angular2 has “almost” one injector per component • There is a tree of injectors, if something is not found in your level, it looks upper • You can nest Angular2 apps (YEAH!) • You can create providers for view models
 (aka no more global model for toggle the state of the search bar)
  • 41. MODULES IN NG2 ANGULAR 2 HAS MULTIPLE INJECTORS import {Component, Input, Output, EventEmitter} from 'angular2/core'; import {RestoreService} from './restore.service'; import {Hero} from ‘./hero'; @Component({ selector: 'hero-editor', providers: [RestoreService], template: … }) export class HeroEditorComponent { … } https://angular.io/docs/ts/latest/guide/hierarchical-dependency-injection.html
  • 42. DISCLAIMER • I’m not an expert in Angular2, just a beginner • I present it because I found very few example and nothing talking about “modules” • I want to share it so I can help others to save time • Tests were done on Angular v2.0.0-beta.1, current is v2.0.0-beta.2, but there is room for change