diff --git a/gulpfile.js b/gulpfile.js index 7950387283..8ca960a8dd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -517,13 +517,15 @@ function installExampleAngular() { var sources; var template; var libs = [ - 'core', 'common', 'compiler', + 'core', 'common', 'compiler', 'compiler-cli', 'platform-browser', 'platform-browser-dynamic', 'forms', 'http', 'router', 'upgrade']; // Like: "angular/core-builds" or "@angular/core" sources = libs.map( lib => argv.build ? `angular/${lib}-builds` : `@angular/${lib}`); + if (argv.build) { sources.push('@angular/tsc-wrapped');} // tsc-wrapped needed for builds + sources.push('@angular/router-deprecated'); gutil.log(`Installing Angular npm packages from ${argv.build ? 'BUILD' : 'RELEASE'}`); diff --git a/package.json b/package.json index 2e848d239c..f13d2126c1 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "protractor": "^3.0.0", "q": "^1.4.1", "tree-kill": "^1.0.0", - "tslint": "^3.2.2", + "tslint": "^3.15.1", "yargs": "^4.7.1" }, "dependencies": { diff --git a/public/docs/_examples/ngmodule/e2e-spec.ts b/public/docs/_examples/ngmodule/e2e-spec.ts index 9279b26fd0..de8f4fa7e0 100644 --- a/public/docs/_examples/ngmodule/e2e-spec.ts +++ b/public/docs/_examples/ngmodule/e2e-spec.ts @@ -6,6 +6,7 @@ describe('NgModule', function () { const gold = 'rgba(255, 215, 0, 1)'; const powderblue = 'rgba(176, 224, 230, 1)'; const lightgray = 'rgba(211, 211, 211, 1)'; + const white = 'rgba(0, 0, 0, 0)'; function getCommonsSectionStruct() { const buttons = element.all(by.css('nav a')); @@ -55,7 +56,7 @@ describe('NgModule', function () { } // tests - function appTitleTests(color: string) { + function appTitleTests(color: string, name?: string) { return function() { it('should have a gray header', function() { const commons = getCommonsSectionStruct(); @@ -64,16 +65,16 @@ describe('NgModule', function () { it('should welcome us', function () { const commons = getCommonsSectionStruct(); - expect(commons.subtitle.getText()).toBe('Welcome, Sam Spade'); + expect(commons.subtitle.getText()).toBe('Welcome, ' + (name || 'Sherlock Holmes')); }); }; } - function contactTests(color: string) { + function contactTests(color: string, name?: string) { return function() { it('shows the contact\'s owner', function() { const contacts = getContactSectionStruct(); - expect(contacts.header.getText()).toBe('Contact of Sam Spade'); + expect(contacts.header.getText()).toBe('Contact of ' + (name || 'Sherlock Holmes')); }); it('can cycle between contacts', function () { @@ -114,9 +115,9 @@ describe('NgModule', function () { browser.get(''); }); - describe('app-title', appTitleTests(lightgray)); + describe('app-title', appTitleTests(white, 'Miss Marple')); - describe('contact', contactTests(lightgray)); + describe('contact', contactTests(lightgray, 'Miss Marple')); describe('crisis center', function () { beforeEach(function () { @@ -149,7 +150,7 @@ describe('NgModule', function () { it('shows a list of heroes', function() { const heroes = getHeroesSectionStruct(); - expect(heroes.header.getText()).toBe('Heroes of Sam Spade'); + expect(heroes.header.getText()).toBe('Heroes of Miss Marple'); expect(heroes.title.getText()).toBe('Hero List'); expect(heroes.items.count()).toBe(6); expect(heroes.items.get(0).getText()).toBe('11 - Mr. Nice'); diff --git a/public/docs/_examples/ngmodule/ts/app/app.module.3.ts b/public/docs/_examples/ngmodule/ts/app/app.module.3.ts index 8aa968a31c..8920c00b61 100644 --- a/public/docs/_examples/ngmodule/ts/app/app.module.3.ts +++ b/public/docs/_examples/ngmodule/ts/app/app.module.3.ts @@ -11,8 +11,6 @@ import { UserService } from './user.service'; /* Feature Modules */ import { ContactModule } from './contact/contact.module.3'; - - import { routing } from './app.routing.3'; @NgModule({ @@ -23,9 +21,8 @@ import { routing } from './app.routing.3'; routing ], // #enddocregion imports - - declarations: [ AppComponent, HighlightDirective, TitleComponent ], providers: [ UserService ], + declarations: [ AppComponent, HighlightDirective, TitleComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } diff --git a/public/docs/_examples/ngmodule/ts/app/app.module.ts b/public/docs/_examples/ngmodule/ts/app/app.module.ts index 7f7ede96e1..cccb49c981 100644 --- a/public/docs/_examples/ngmodule/ts/app/app.module.ts +++ b/public/docs/_examples/ngmodule/ts/app/app.module.ts @@ -1,29 +1,40 @@ // #docplaster // #docregion +// #docregion v4 import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; /* App Root */ import { AppComponent } from './app.component'; - - - /* Feature Modules */ import { ContactModule } from './contact/contact.module'; -import { SharedModule } from './shared/shared.module'; - +import { CoreModule } from './core/core.module'; import { routing } from './app.routing'; @NgModule({ + // #docregion import-for-root imports: [ BrowserModule, ContactModule, - routing, - SharedModule.forRoot() +// #enddocregion v4 +// #enddocregion +// #enddocregion import-for-root +/* +// #docregion v4 + CoreModule, +// #enddocregion v4 +*/ +// #docregion import-for-root +// #docregion + CoreModule.forRoot({userName: 'Miss Marple'}), +// #docregion v4 + routing ], + // #enddocregion import-for-root declarations: [ AppComponent ], - bootstrap: [ AppComponent ] }) export class AppModule { } +// #enddocregion v4 +// #enddocregion diff --git a/public/docs/_examples/ngmodule/ts/app/contact/contact.component.ts b/public/docs/_examples/ngmodule/ts/app/contact/contact.component.ts index 9bf9bc0ee9..2a60cda1f3 100644 --- a/public/docs/_examples/ngmodule/ts/app/contact/contact.component.ts +++ b/public/docs/_examples/ngmodule/ts/app/contact/contact.component.ts @@ -1,9 +1,9 @@ -// Exact copy except import UserService from shared +// Exact copy except import UserService from core // #docregion import { Component, OnInit } from '@angular/core'; import { Contact, ContactService } from './contact.service'; -import { UserService } from '../shared/user.service'; +import { UserService } from '../core/user.service'; @Component({ selector: 'app-contact', diff --git a/public/docs/_examples/ngmodule/ts/app/contact/contact.module.3.ts b/public/docs/_examples/ngmodule/ts/app/contact/contact.module.3.ts index d28d67d085..6f835635d0 100644 --- a/public/docs/_examples/ngmodule/ts/app/contact/contact.module.3.ts +++ b/public/docs/_examples/ngmodule/ts/app/contact/contact.module.3.ts @@ -15,7 +15,6 @@ import { routing } from './contact.routing.3'; @NgModule({ imports: [ CommonModule, FormsModule, routing ], declarations: [ ContactComponent, HighlightDirective, AwesomePipe ], - providers: [ ContactService ] }) export class ContactModule { } diff --git a/public/docs/_examples/ngmodule/ts/app/contact/contact.routing.3.ts b/public/docs/_examples/ngmodule/ts/app/contact/contact.routing.3.ts index 5490649283..63d740d82e 100644 --- a/public/docs/_examples/ngmodule/ts/app/contact/contact.routing.3.ts +++ b/public/docs/_examples/ngmodule/ts/app/contact/contact.routing.3.ts @@ -1,7 +1,7 @@ import { ModuleWithProviders } from '@angular/core'; -import { RouterModule } from '@angular/router'; +import { RouterModule } from '@angular/router'; -import { ContactComponent } from './contact.component.3'; +import { ContactComponent } from './contact.component.3'; export const routing: ModuleWithProviders = RouterModule.forChild([ { path: 'contact', component: ContactComponent} diff --git a/public/docs/_examples/ngmodule/ts/app/contact/contact.routing.ts b/public/docs/_examples/ngmodule/ts/app/contact/contact.routing.ts index 065e78dabd..6b6534dfbc 100644 --- a/public/docs/_examples/ngmodule/ts/app/contact/contact.routing.ts +++ b/public/docs/_examples/ngmodule/ts/app/contact/contact.routing.ts @@ -1,7 +1,7 @@ import { ModuleWithProviders } from '@angular/core'; -import { RouterModule } from '@angular/router'; +import { RouterModule } from '@angular/router'; -import { ContactComponent } from './contact.component'; +import { ContactComponent } from './contact.component'; // #docregion routing export const routing: ModuleWithProviders = RouterModule.forChild([ diff --git a/public/docs/_examples/ngmodule/ts/app/core/core.module.ts b/public/docs/_examples/ngmodule/ts/app/core/core.module.ts new file mode 100644 index 0000000000..1a92416012 --- /dev/null +++ b/public/docs/_examples/ngmodule/ts/app/core/core.module.ts @@ -0,0 +1,48 @@ +/* tslint:disable:member-ordering no-unused-variable */ +// #docplaster +// #docregion +// #docregion v4 +import { + BaseException, ModuleWithProviders, + NgModule, Optional, SkipSelf } from '@angular/core'; + +import { CommonModule } from '@angular/common'; + +import { TitleComponent } from './title.component'; +import { UserService } from './user.service'; +// #enddocregion +import { UserServiceConfig } from './user.service'; + +// #docregion v4 +@NgModule({ + imports: [ CommonModule ], + declarations: [ TitleComponent ], + exports: [ TitleComponent ], + providers: [ UserService ] +}) +export class CoreModule { +// #enddocregion v4 + + // #docregion ctor + constructor (@Optional() @SkipSelf() parentModule: CoreModule) { + if (parentModule) { + throw new BaseException( + 'CoreModule is already loaded. Import it in the AppModule only'); + } + } + // #enddocregion ctor + + // #docregion for-root + static forRoot(config: UserServiceConfig): ModuleWithProviders { + return { + ngModule: CoreModule, + providers: [ + {provide: UserServiceConfig, useValue: config } + ] + }; + } + // #enddocregion for-root +// #docregion v4 +} +// #enddocregion v4 +// #enddocregion diff --git a/public/docs/_examples/ngmodule/ts/app/shared/title.component.html b/public/docs/_examples/ngmodule/ts/app/core/title.component.html similarity index 63% rename from public/docs/_examples/ngmodule/ts/app/shared/title.component.html rename to public/docs/_examples/ngmodule/ts/app/core/title.component.html index 6108c38415..8ebd08ae43 100644 --- a/public/docs/_examples/ngmodule/ts/app/shared/title.component.html +++ b/public/docs/_examples/ngmodule/ts/app/core/title.component.html @@ -1,4 +1,4 @@ - +
Welcome, {{user}}
diff --git a/public/docs/_examples/ngmodule/ts/app/shared/title.component.ts b/public/docs/_examples/ngmodule/ts/app/core/title.component.ts
similarity index 77%
rename from public/docs/_examples/ngmodule/ts/app/shared/title.component.ts
rename to public/docs/_examples/ngmodule/ts/app/core/title.component.ts
index c3f35b5d32..ca8cffe9d5 100644
--- a/public/docs/_examples/ngmodule/ts/app/shared/title.component.ts
+++ b/public/docs/_examples/ngmodule/ts/app/core/title.component.ts
@@ -1,10 +1,10 @@
// Exact copy of app/title.component.ts except import UserService from shared
import { Component, Input } from '@angular/core';
-import { UserService } from './user.service';
+import { UserService } from '../core/user.service';
@Component({
selector: 'app-title',
- templateUrl: 'app/shared/title.component.html',
+ templateUrl: 'app/core/title.component.html',
})
export class TitleComponent {
@Input() subtitle = '';
diff --git a/public/docs/_examples/ngmodule/ts/app/core/user.service.ts b/public/docs/_examples/ngmodule/ts/app/core/user.service.ts
new file mode 100644
index 0000000000..8fe839075e
--- /dev/null
+++ b/public/docs/_examples/ngmodule/ts/app/core/user.service.ts
@@ -0,0 +1,32 @@
+// Crazy copy of the app/user.service
+// Proves that UserService is an app-wide singleton and only instantiated once
+// IFF shared.module follows the `forRoot` pattern
+//
+// If it didn't, a new instance of UserService would be created
+// after each lazy load and the userName would double up.
+
+import { Injectable, Optional } from '@angular/core';
+
+let nextId = 1;
+
+export class UserServiceConfig {
+ userName = 'Philip Marlowe';
+}
+
+@Injectable()
+export class UserService {
+ id = nextId++;
+ private _userName = 'Sherlock Holmes';
+
+ // #docregion ctor
+ constructor(@Optional() config: UserServiceConfig) {
+ if (config) { this._userName = config.userName; }
+ }
+ // #enddocregion ctor
+
+ get userName() {
+ // Demo: add a suffix if this service has been created more than once
+ const suffix = this.id > 1 ? ` times ${this.id}` : '';
+ return this._userName + suffix;
+ }
+}
diff --git a/public/docs/_examples/ngmodule/ts/app/crisis/crisis-detail.component.ts b/public/docs/_examples/ngmodule/ts/app/crisis/crisis-detail.component.ts
index da9efb3b2b..9749029d62 100644
--- a/public/docs/_examples/ngmodule/ts/app/crisis/crisis-detail.component.ts
+++ b/public/docs/_examples/ngmodule/ts/app/crisis/crisis-detail.component.ts
@@ -1,5 +1,5 @@
-import { Component, OnInit } from '@angular/core';
-import { ActivatedRoute } from '@angular/router';
+import { Component, OnInit } from '@angular/core';
+import { ActivatedRoute } from '@angular/router';
@Component({
template: `
diff --git a/public/docs/_examples/ngmodule/ts/app/crisis/crisis.routing.ts b/public/docs/_examples/ngmodule/ts/app/crisis/crisis.routing.ts
index c9aeb83d5f..4d8d711d65 100644
--- a/public/docs/_examples/ngmodule/ts/app/crisis/crisis.routing.ts
+++ b/public/docs/_examples/ngmodule/ts/app/crisis/crisis.routing.ts
@@ -1,6 +1,6 @@
import { ModuleWithProviders } from '@angular/core';
import { Routes,
- RouterModule } from '@angular/router';
+ RouterModule } from '@angular/router';
import { CrisisListComponent } from './crisis-list.component';
import { CrisisDetailComponent } from './crisis-detail.component';
diff --git a/public/docs/_examples/ngmodule/ts/app/hero/hero.component.ts b/public/docs/_examples/ngmodule/ts/app/hero/hero.component.ts
index 3329e25cc0..86338fb0ae 100644
--- a/public/docs/_examples/ngmodule/ts/app/hero/hero.component.ts
+++ b/public/docs/_examples/ngmodule/ts/app/hero/hero.component.ts
@@ -1,8 +1,8 @@
-// Exact copy except import UserService from shared
+// Exact copy except import UserService from core
import { Component } from '@angular/core';
import { HeroService } from './hero.service';
-import { UserService } from '../shared/user.service';
+import { UserService } from '../core/user.service';
@Component({
template: `
diff --git a/public/docs/_examples/ngmodule/ts/app/hero/hero.module.3.ts b/public/docs/_examples/ngmodule/ts/app/hero/hero.module.3.ts
index def1432fc4..327e528178 100644
--- a/public/docs/_examples/ngmodule/ts/app/hero/hero.module.3.ts
+++ b/public/docs/_examples/ngmodule/ts/app/hero/hero.module.3.ts
@@ -1,12 +1,12 @@
-import { NgModule } from '@angular/core';
-import { CommonModule } from '@angular/common';
-import { FormsModule } from '@angular/forms';
+import { NgModule } from '@angular/core';
+import { CommonModule } from '@angular/common';
+import { FormsModule } from '@angular/forms';
-import { HeroComponent } from './hero.component.3';
-import { HeroDetailComponent } from './hero-detail.component';
-import { HeroListComponent } from './hero-list.component';
-import { HighlightDirective } from './highlight.directive';
-import { routing } from './hero.routing.3';
+import { HeroComponent } from './hero.component.3';
+import { HeroDetailComponent } from './hero-detail.component';
+import { HeroListComponent } from './hero-list.component';
+import { HighlightDirective } from './highlight.directive';
+import { routing } from './hero.routing.3';
// #docregion class
@NgModule({
diff --git a/public/docs/_examples/ngmodule/ts/app/hero/hero.module.ts b/public/docs/_examples/ngmodule/ts/app/hero/hero.module.ts
index d49455fa0b..5408205a3d 100644
--- a/public/docs/_examples/ngmodule/ts/app/hero/hero.module.ts
+++ b/public/docs/_examples/ngmodule/ts/app/hero/hero.module.ts
@@ -1,11 +1,11 @@
-import { NgModule } from '@angular/core';
+import { NgModule } from '@angular/core';
-import { SharedModule } from '../shared/shared.module';
+import { SharedModule } from '../shared/shared.module';
-import { HeroComponent } from './hero.component';
-import { HeroDetailComponent } from './hero-detail.component';
-import { HeroListComponent } from './hero-list.component';
-import { routing } from './hero.routing';
+import { HeroComponent } from './hero.component';
+import { HeroDetailComponent } from './hero-detail.component';
+import { HeroListComponent } from './hero-list.component';
+import { routing } from './hero.routing';
/*
* TODO: Remove THE HeroService class and provider after
diff --git a/public/docs/_examples/ngmodule/ts/app/hero/hero.routing.3.ts b/public/docs/_examples/ngmodule/ts/app/hero/hero.routing.3.ts
index e14d4a7725..132d21b29e 100644
--- a/public/docs/_examples/ngmodule/ts/app/hero/hero.routing.3.ts
+++ b/public/docs/_examples/ngmodule/ts/app/hero/hero.routing.3.ts
@@ -1,10 +1,10 @@
import { ModuleWithProviders } from '@angular/core';
import { Routes,
- RouterModule } from '@angular/router';
+ RouterModule } from '@angular/router';
-import { HeroComponent } from './hero.component.3';
-import { HeroListComponent } from './hero-list.component';
-import { HeroDetailComponent } from './hero-detail.component';
+import { HeroComponent } from './hero.component.3';
+import { HeroListComponent } from './hero-list.component';
+import { HeroDetailComponent } from './hero-detail.component';
const routes: Routes = [
{ path: '',
diff --git a/public/docs/_examples/ngmodule/ts/app/hero/hero.routing.ts b/public/docs/_examples/ngmodule/ts/app/hero/hero.routing.ts
index 7f364ee988..f1b4285ecd 100644
--- a/public/docs/_examples/ngmodule/ts/app/hero/hero.routing.ts
+++ b/public/docs/_examples/ngmodule/ts/app/hero/hero.routing.ts
@@ -1,10 +1,10 @@
import { ModuleWithProviders } from '@angular/core';
import { Routes,
- RouterModule } from '@angular/router';
+ RouterModule } from '@angular/router';
-import { HeroComponent } from './hero.component';
-import { HeroListComponent } from './hero-list.component';
-import { HeroDetailComponent } from './hero-detail.component';
+import { HeroComponent } from './hero.component';
+import { HeroListComponent } from './hero-list.component';
+import { HeroDetailComponent } from './hero-detail.component';
const routes: Routes = [
{ path: '',
diff --git a/public/docs/_examples/ngmodule/ts/app/shared/shared.module.ts b/public/docs/_examples/ngmodule/ts/app/shared/shared.module.ts
index 5991278d44..2da7d7b2a5 100644
--- a/public/docs/_examples/ngmodule/ts/app/shared/shared.module.ts
+++ b/public/docs/_examples/ngmodule/ts/app/shared/shared.module.ts
@@ -1,40 +1,18 @@
// #docregion
-import { NgModule,
- ModuleWithProviders } from '@angular/core';
+import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { AwesomePipe } from './awesome.pipe';
import { HighlightDirective } from './highlight.directive';
-import { TitleComponent } from './title.component';
-import { UserService } from './user.service';
-// #docregion shared-module
+// #docregion module
@NgModule({
imports: [ CommonModule ],
- declarations: [ AwesomePipe, HighlightDirective, TitleComponent ],
- exports: [ AwesomePipe, HighlightDirective, TitleComponent,
+ declarations: [ AwesomePipe, HighlightDirective ],
+ exports: [ AwesomePipe, HighlightDirective,
CommonModule, FormsModule ]
})
-export class SharedModule {
-
-// #docregion for-root
- static forRoot(): ModuleWithProviders {
- return {
- ngModule: SharedModule,
- providers: [ UserService ]
- };
- }
-// #enddocregion for-root
-}
-
-// #enddocregion shared-module
+export class SharedModule { }
+// #enddocregion module
// #enddocregion
-
-// #docregion shared-root-module
-@NgModule({
- exports: [ SharedModule ],
- providers: [ UserService ]
-})
-export class SharedRootModule { }
-// #enddocregion shared-root-module
diff --git a/public/docs/_examples/ngmodule/ts/app/shared/user.service.ts b/public/docs/_examples/ngmodule/ts/app/shared/user.service.ts
deleted file mode 100644
index d32b20b043..0000000000
--- a/public/docs/_examples/ngmodule/ts/app/shared/user.service.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-// Crazy copy of the app/user.service
-// Proves that UserService is an app-wide singleton and only instantiated once
-// IFF shared.module follows the `forRoot` pattern
-//
-// If it didn't, a new instance of UserService would be created
-// after each lazy load and the userName would double up.
-
-import { Injectable } from '@angular/core';
-
-@Injectable()
-export class UserService {
-
- static userName = '';
-
- constructor() {
- UserService.userName += UserService.userName || 'Sam Spade';
- }
-
- get userName() { return UserService.userName; }
-}
diff --git a/public/docs/_examples/ngmodule/ts/app/user.service.ts b/public/docs/_examples/ngmodule/ts/app/user.service.ts
index cf31db5da5..7d996b26fa 100644
--- a/public/docs/_examples/ngmodule/ts/app/user.service.ts
+++ b/public/docs/_examples/ngmodule/ts/app/user.service.ts
@@ -4,5 +4,5 @@ import { Injectable } from '@angular/core';
@Injectable()
/** Dummy version of an authenticated user service */
export class UserService {
- userName = 'Sam Spade';
+ userName = 'Sherlock Holmes';
}
diff --git a/public/docs/_examples/ngmodule/ts/plnkr.json b/public/docs/_examples/ngmodule/ts/plnkr.json
index 54b3da8310..fabaf6a014 100644
--- a/public/docs/_examples/ngmodule/ts/plnkr.json
+++ b/public/docs/_examples/ngmodule/ts/plnkr.json
@@ -22,6 +22,10 @@
"!app/hero/hero.routing.3.ts",
"!app/hero/highlight.directive.ts",
+ "app/core/*.css",
+ "app/core/*.html",
+ "app/core/*.ts",
+
"app/shared/*.css",
"app/shared/*.html",
"app/shared/*.ts",
diff --git a/public/docs/_examples/package.json b/public/docs/_examples/package.json
index 6c253c3e4c..8f9f6a335a 100644
--- a/public/docs/_examples/package.json
+++ b/public/docs/_examples/package.json
@@ -27,6 +27,7 @@
"dependencies": {
"@angular/common": "2.0.0-rc.5",
"@angular/compiler": "2.0.0-rc.5",
+ "@angular/compiler-cli": "0.5.0",
"@angular/core": "2.0.0-rc.5",
"@angular/forms": "0.3.0",
"@angular/http": "2.0.0-rc.5",
@@ -47,7 +48,7 @@
"angular-cli": "^1.0.0-beta.5",
"angular2-template-loader": "^0.4.0",
"canonical-path": "0.0.2",
- "concurrently": "^2.1.0",
+ "concurrently": "^2.2.0",
"css-loader": "^0.23.1",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.8.5",
@@ -63,7 +64,7 @@
"karma-phantomjs-launcher": "^1.0.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.7.0",
- "lite-server": "^2.2.0",
+ "lite-server": "^2.2.2",
"lodash": "^4.13.1",
"null-loader": "^0.1.1",
"phantomjs-prebuilt": "^2.1.7",
@@ -73,9 +74,9 @@
"style-loader": "^0.13.1",
"ts-loader": "^0.8.2",
"ts-node": "^0.7.3",
- "tslint": "^3.13.0",
+ "tslint": "^3.15.1",
"typescript": "^1.8.10",
- "typings": "^1.0.4",
+ "typings": "^1.3.2",
"webpack": "^1.13.0",
"webpack-dev-server": "^1.14.1",
"webpack-merge": "^0.14.0"
diff --git a/public/docs/_examples/quickstart/ts/package.1.json b/public/docs/_examples/quickstart/ts/package.1.json
index 4f0bc098fd..244ca9514d 100644
--- a/public/docs/_examples/quickstart/ts/package.1.json
+++ b/public/docs/_examples/quickstart/ts/package.1.json
@@ -13,28 +13,28 @@
"dependencies": {
"@angular/common": "2.0.0-rc.5",
"@angular/compiler": "2.0.0-rc.5",
+ "@angular/compiler-cli": "0.5.0",
"@angular/core": "2.0.0-rc.5",
"@angular/forms": "0.3.0",
"@angular/http": "2.0.0-rc.5",
"@angular/platform-browser": "2.0.0-rc.5",
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
"@angular/router": "3.0.0-rc.1",
- "@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.5",
- "systemjs": "0.19.27",
"core-js": "^2.4.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
+ "systemjs": "0.19.27",
"zone.js": "^0.6.12",
- "angular2-in-memory-web-api": "0.0.15",
+ "angular2-in-memory-web-api": "0.0.17",
"bootstrap": "^3.3.6"
},
"devDependencies": {
- "concurrently": "^2.0.0",
- "lite-server": "^2.2.0",
+ "concurrently": "^2.2.0",
+ "lite-server": "^2.2.2",
"typescript": "^1.8.10",
- "typings":"^1.0.4"
+ "typings":"^1.3.2"
}
}
diff --git a/public/docs/_examples/systemjs.config.js b/public/docs/_examples/systemjs.config.js
index 2fb97dbfc8..9992b829c0 100644
--- a/public/docs/_examples/systemjs.config.js
+++ b/public/docs/_examples/systemjs.config.js
@@ -40,7 +40,7 @@
// Bundled (~40 requests):
function packUmd(pkgName) {
- packages['@angular/'+pkgName] = { main: 'bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
+ packages['@angular/'+pkgName] = { main: 'bundles/' + pkgName + '.umd.js' };
}
// Most environments should use UMD; some (Karma) need the individual index files
diff --git a/public/docs/_examples/systemjs.config.plunker.js b/public/docs/_examples/systemjs.config.plunker.js
index d55c4db274..d8f55b2c0a 100644
--- a/public/docs/_examples/systemjs.config.plunker.js
+++ b/public/docs/_examples/systemjs.config.plunker.js
@@ -51,7 +51,7 @@
ngPackageNames.concat(['forms', 'router', 'router-deprecated']).forEach(function(pkgName) {
// Bundled (~40 requests):
- packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
+ packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js' };
// Individual files (~300 requests):
//packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
diff --git a/public/docs/ts/latest/guide/ngmodule.jade b/public/docs/ts/latest/guide/ngmodule.jade
index 3fe18bc9a2..697cbe9c1a 100644
--- a/public/docs/ts/latest/guide/ngmodule.jade
+++ b/public/docs/ts/latest/guide/ngmodule.jade
@@ -23,10 +23,25 @@ block includes
* [Resolve conflicts](#resolve-conflicts "When two directives have the same selector ...")
* [Feature modules](#feature-modules "Partition the app into feature modules")
* [Lazy loaded modules](#lazy-load "Load modules asynchronously") with the Router
- * [Shared modules](#shared-module "Create a module for commonly used components, directives, pipes and services")
+ * [Shared modules](#shared-module "Create modules for commonly used components, directives, and pipes")
+ * [The Core module](#core-module "Create a core module with app-wide singleton services and single-use components")
+ * [Configure core services with _forRoot_](#core-for-root "Configure providers during module import")
+ * [Prevent reimport of the _CoreModule_](#prevent-reimport "because bad things happen if a lazy loaded module imports Core")
* [NgModule metadata properties](#ngmodule-properties "A technical summary of the @NgModule metadata properties")
* [FAQ](#faq "Frequently asked questions")
+ ### Live examples
+ This chapter explains Angular Modules through a progression of improvements to a sample with a "Tour of Heroes" theme.
+ Here's an index to live examples at key moments in the evolution of that sample:
+
+ * declarations
td
:marked
- A list of the **component**, **directive** and **pipe** classes that _belong to this module_.
+ A list of [declarable](#q-declarables) classes,
+ the **component**, **directive** and **pipe** classes that _belong to this module_.
These declared classes are visible within the module but invisible to
components in a different module unless (a) they are _exported_ from this module and
@@ -1065,24 +1195,31 @@ a#faq
Declarations
* [What classes should I add to _declarations_?](#q-what-to-declare)
+ * [What is a _declarable_?](#q-declarable)
* [What classes should I *not* add to _declarations_?](#q-what-not-to-declare)
- * [Why list the same component in multiple module properties?](#q-why-multiple-mentions)
- * [What does "_Can't bind to 'x' since it isn't a known property of 'y'_" mean?](q-why-cant-bind-to)
+ * [Why list the same component in multiple _NgModule_ properties?](#q-why-multiple-mentions)
+ * [What does "_Can't bind to 'x' since it isn't a known property of 'y'_" mean?](#q-why-cant-bind-to)
- Imports and Exports
+ Imports
* [What should I import?](#q-what-to-import)
+ * [Should I import _BrowserModule_ or _CommonModule_?](#q-browser-vs-common-module)
* [What if I import the same module twice?](#q-reimport)
+
+ Exports
* [What should I export?](#q-what-to-export)
* [What should I *not* export?](#q-what-not-to-export)
* [Can I re-export imported classes and modules?](#q-re-export)
+ * [What is the _forRoot_ method?](#q-for-root)
Service Providers
* [Why is a service provided in a feature module visible everywhere?](#q-module-provider-visibility)
- * [Why is a service provided in a _lazy loaded_ module visible only to that module?](q-lazy-loaded-module-provider-visibility)
+ * [Why is a service provided in a _lazy loaded_ module visible only to that module?](#q-lazy-loaded-module-provider-visibility)
* [What if two modules provide the _same_ service?](#q-module-provider-duplicates)
* [How do I restrict service scope to a module?](#q-component-scoped-providers)
* [Should I add providers to the root _AppModule_ or the root _AppComponent_?](#q-root-component-or-module)
- * [Why is it bad if _SharedModule_ provides the _UserService_ to every app module?](#q-why-it-is-bad)
+ * [Why is it bad if _SharedModule_ provides a service to a lazy loaded module?](#q-why-it-is-bad)
+ * [Why does lazy loading create a child injector?](#q-why-child-injector)
+ * [How can I tell if a module or service was previously loaded?](#q-is-it-loaded)
Entry Components
* [What is an _entry component_?](#q-entry-component-defined)
@@ -1090,11 +1227,12 @@ a#faq
* [When do I add components to _entryComponents_?](#q-when-entry-components)
* [Why does Angular need _entryComponents_?](#q-why-entry-components)
- Miscellaneous
+ General
+ * [What kinds of modules should I have and how should I use them?](#q-module-recommendations)
+ * [What's the difference between Angular and JavaScript Modules?](#q-ng-vs-js-modules)
* [What is a "template reference"?](#q-template-reference)
* [How does Angular find components, directives, and pipes in a template?](#q-template-reference)
* [What is the Angular Compiler?](#q-angular-compiler)
- * [What's the difference between Angular and JavaScript Modules?](#q-ng-vs-js-modules)
.l-hr
@@ -1103,24 +1241,39 @@ a#q-what-to-declare
:marked
### What classes should I add to _declarations_?
- Add components, directives, and pipes to a `declarations` list.
+ Add [declarable](#q-declarable) classes — components, directives, and pipes — to a `declarations` list.
- These kinds of classes must be declared in _exactly one_ module of the application.
+ These classes must be declared in _exactly one_ module of the application.
Declare them in _this_ module if they _belong_ to this module.
.l-hr
+a#q-declarable
+.l-main-section
+:marked
+ ### What is a _declarable_?
+
+ _Declarables_ are the class types — components, directives, and pipes —
+ that you can add to a module's `declarations` list.
+ They're the _only_ classes that you can add to `declarations`.
+
+.l-hr
+
a#q-what-not-to-declare
.l-main-section
:marked
### What classes should I _not_ add to _declarations_?
+ Only [declarable](#q-declarable) classes can be added to a module's `declarations` list.
+
Do *not* declare
* a class that is already declared in another module, whether an app module, @angular module, or 3rd party module
* an array of directives imported from another module.
For example, do not declare FORMS_DIRECTIVES from `@angular/forms`.
+ * module classes
+
* service classes
* non-Angular classes and objects such as
@@ -1131,9 +1284,9 @@ a#q-what-not-to-declare
a#q-why-multiple-mentions
.l-main-section
:marked
- ### Why list the same component in multiple module properties?
+ ### Why list the same component in multiple _NgModule_ properties?
- For example, we often see `AppComponent` listed in both `declarations` and `bootstrap`.
+ We often see `AppComponent` listed in both `declarations` and `bootstrap`.
We might see `HeroComponent` listed in `declarations`, `exports`, and `entryComponents`.
That _feels_ redundant but these properties have different functions
@@ -1166,25 +1319,44 @@ a#q-what-to-import
:marked
### What should I import?
+ Import modules whose public (exported) [declarable classes](#q-declarable)
+ you need to reference in this module's component templates.
+
+ This invariably means importing `CommonModule` from `@angular/common` for access to
+ the Angular directives such as `NgIf` and `NgFor`.
+ You can import it directly or from another module that [re-exports](#q-reexport) it.
+
+ Import `FormsModule` from `@angular/forms`
+ if your components have `[(ngModel)]` two-way binding expressions.
+
+ Import _shared_ and _feature_ modules when this module's components incorporate their
+ components, directives, and pipes.
+
+ Only [import _BrowserModule_](#q-browser-vs-common-module) in the root `AppModule`.
+
+.l-hr
+
+a#q-browser-vs-common-module
+.l-main-section
+:marked
+ ### Should I import _BrowserModule_ or _CommonModule_?
+
The **root application module** (`AppModule`) of almost every browser application
should import `BrowserModule` from `@angular/core`.
`BrowserModule` provides services that are essential to launch and run a browser app.
- It also re-exports `CommonModule` from `@angular/common`
- which means that `AppModule` module components have access to
- that common directives almost every app needs such as `NgIf` and `NgFor`.
+ `BrowserModule` also re-exports `CommonModule` from `@angular/common`
+ which means that component in the `AppModule` module also have access to
+ the Angular directives every app needs such as `NgIf` and `NgFor`.
- Application *feature modules* and *lazy loaded modules* should import `CommonModule` instead.
-
- ***They should not import `BrowserModule`***.
-
- A feature module that imports `BrowserModule` could redefine the platform providers
- that were originally registered in a previously imported module.
-
- The risk is greater with lazy loaded modules because they have their own injector.
- Importing `BrowserModule` could block access to the corresponding service instances in the root injector.
-
+ _Do not import_ `BrowserModule` in any other module.
+ *Feature modules* and *lazy loaded modules* should import `CommonModule` instead.
+ They need the common directives. They don't need to re-install the app-wide providers.
+.l-sub-section
+ :marked
+ `BrowserModule` throws an error if you try to lazy load a module that imports it.
+:marked
Importing `CommonModule` also frees feature modules for use on _any_ target platform, not just browsers,
a fact of some interest to authors of cross-platform libraries.
@@ -1210,13 +1382,16 @@ a#q-what-to-export
:marked
### What should I export?
- Only export "public classes", the classes that external components should be allowed to incorporate in their templates.
+ Export [declarable](#q-declarable) classes that components in _other_ modules
+ should be able to reference in their templates. These are your _public_ classes.
+ If you don't export a class, it stays _private_, visible only to other component
+ declared in this module.
You _can_ export any declarable class — components, directives, and pipes —
- whether declared in this module or in an imported module.
+ whether it is declared in this module or in an imported module.
You _can_ re-export entire imported modules which effectively re-exports all of their exported classes.
- A module can even export a module that it doesn't import as long as it doesn't need anything from that module.
+ A module can even export a module that it doesn't import.
.l-hr
@@ -1227,15 +1402,19 @@ a#q-what-not-to-export
Do *not* export
- * The components, directives, and pipes that should be used privately,
- strictly within templates of the components declared in this module.
+ * Private components, directives, and pipes that you need only within components declared in this module.
+ If you don't want another module to see it, don't export it.
- * Non-declarable objects such as services, functions, configurations, entity models, etc.
+ * Non-declarable objects such as services, functions, configurations, entity models, etc.
- * Components that are only loaded dynamically by the router or by bootstrapping.
+ * Components that are only loaded dynamically by the router or by bootstrapping.
Such [entry components](#q-entry-component-defined) can never be selected in another component's template.
There's no harm in exporting them but no benefit either.
+ * Pure service modules that don't have public (exported) declarations.
+ For example, there is no point in re-exporting `HttpModule` because it doesn't export anything.
+ It's only purpose is to add http service providers to the application as a whole.
+
.l-hr
a#q-reexport
@@ -1256,6 +1435,40 @@ code-example.
:marked
A module can export a combination of its own declarations, selected imported classes, and imported modules.
+.l-sub-section
+ :marked
+ Don't bother re-exporting pure service modules.
+ Pure service modules don't export [declarable](#q-declarable) classes that another module could use.
+ For example, there is no point in re-exporting `HttpModule` because it doesn't export anything.
+ It's only purpose is to add http service providers to the application as a whole.
+
+.l-hr
+
+a#q-for-root
+.l-main-section
+:marked
+ ### What is the _forRoot_ method?
+
+ The `forRoot` static method is a convention that makes it easy for developers to configure the module's provider(s).
+
+ The `RouterModule.forRoot` method is a good example.
+ Apps pass a `Routes` object to `RouterModule.forRoot` in order to configure the app-wide `Router` service with routes.
+ `RouterModule.forRoot` returns a [ModuleWithProviders](../api/core/index/ModuleWithProviders-interface.html).
+ We add that result to the `imports` list of the root `AppModule`.
+
+.alert.is-important
+ :marked
+ Only call and import a `.forRoot` result in the root application module, `AppModule`.
+ Importing it in any other module, particularly in a lazy loaded module,
+ is contrary to the intent and is likely to produce a runtime error.
+:marked
+ `RouterModule` also offers a `forChild` static method for configuring the routes of lazy loaded modules.
+
+ **_forRoot_** and **_forChild_** are conventional names for methods that
+ configure services in root and feature modules respectively.
+
+ Angular doesn't recognize these names but Angular developers do.
+ Follow this convention when you write similar modules with configurable service providers.
.l-hr
@@ -1296,16 +1509,15 @@ a#q-lazy-loaded-module-provider-visibility
providers of lazy loaded modules are *module-scoped*.
When the Angular router lazy-loads a module, it creates a new execution context.
- That context has its own injector which is a direct child of the application injector.
+ That [context has its own injector](#q-why-child-injector "Why Angular creates a child injector") which is a direct child of the application injector.
- The router adds the lazy module's own providers and the providers of its imported modules to this child injector.
+ The router adds the lazy module's providers and the providers of its imported modules to this child injector.
These providers are insulated from changes to application providers with the same lookup token.
When the router creates a component within the lazy loaded context,
Angular prefers service instances created from these providers to the service instances of the application root injector.
.l-hr
-
a#q-module-provider-duplicates
.l-main-section
:marked
@@ -1429,34 +1641,90 @@ a#q-root-component-or-module
a#q-why-it-is-bad
.l-main-section
:marked
- ### Why is it bad if _SharedModule_ provides the _UserService_ to every app module?
+ ### Why is it bad if _SharedModule_ provides a service to a lazy loaded module?
- This question arose when we described the [_SharedModule.forRoot_](#shared-module-for-root) method.
+ This question arose earlier when we discussed the importance
+ of keeping providers out of the [_SharedModule_](#no-shared-module-providers).
- Suppose we had listed the service in the module's `providers` (which we did not).
+ Suppose we had listed the `UserService` in the module's `providers` (which we did not).
Suppose every module imports this `SharedModule` (which they all do).
- When the app starts, Angular loads the `AppModule` and the `ContactModule`.
- Both instances of the imported `SharedModule` provide the `UserService`.
- Angular registers one of them in the root app injector.
- A component requests it and we have our app-wide singleton `UserService`. No problem.
+ When the app starts, Angular eagerly loads the `AppModule` and the `ContactModule`.
+
+ Both instances of the imported `SharedModule` would provide the `UserService`.
+ Angular registers one of them in the root app injector (see [above](#q-reimport)).
+ Then some component injects `UserService`, Angular finds it in the app root injector,
+ and delivers the app-wide singleton `UserService`. No problem.
+
+ Now consider the `HeroModule` _which is lazy loaded!_
- But the `HeroModule` is lazy loaded!
When the router lazy loads the `HeroModule`, it creates a child injector and registers the `UserService`
- with that child injector. The child injector is _not_ the root injector.
- When Angular injects the `UserService` into the `HeroComponent`,
- it creates and injects a new instance of the `UserService`.
- That's a disaster.
+ provider with that child injector. The child injector is _not_ the root injector.
+
+ When Angular creates a lazy `HeroComponent`, it must inject a `UserService`.
+ This time it finds a `UserService` provider in the lazy module's _child injector_
+ and creates a _new_ instance of the `UserService`.
+ This is an entirely different `UserService` instance
+ than the app-wide singleton version that Angular injected in one of the eagerly loaded components.
+
+ That's almost certainly a mistake.
.l-sub-section
:marked
Prove it for yourself.
Run the AppModule
+ td ContactModule (before routing)
+ tr
+ td Routed
+ td Yes
+ td Rare
+ td None
+ td Nobody
+ td ContactModule, HeroModule, CrisisModule
+ tr
+ td Service
+ td No
+ td Yes
+ td No
+ td AppModule
+ td HttpModule, CoreModule
+ tr
+ td Widget
+ td Yes
+ td Rare
+ td Yes
+ td Feature
+ td CommonModule, SharedModule
+
+.l-hr
+
+a#q-ng-vs-js-modules
+.l-main-section
+:marked
+ ### What's the difference between Angular and JavaScript Modules?
+
+ Angular and JavaScript are two different yet complementary module systems.
+
+ In modern JavaScript, [every file is a _module_](http://exploringjs.com/es6/ch_modules.html).
+ Within each file we write an `export` statement to make parts of the module public:
+
+code-example(format='.').
+ export class AppComponent { ... }
+
+:marked
+ Then we `import` a part in another module:
+
+code-example(format='.').
+ import { AppComponent } from './app.component';
+
+:marked
+ This kind of modularity is a feature of the _JavaScript language_.
+
+ An _Angular Module_ is a feature of _Angular_ itself.
+
+ Angular's `NgModule` also has `imports` and `exports` and they serve a similar purpose.
+
+ We _import_ other Angular modules so we can use their exported classes in component templates.
+ We _export_ this Angular module's classes so they can be imported and used by components of _other_ modules.
+
+ The Angular module classes differ from JavaScript module class in three key respects:
+
+ 1. An Angular module bounds [_declarable classes_](#q-declarables) only.
+ Declarables are the only classes that matter to the [Angular compiler](#angular-compiler).
+
+ 1. Instead of defining all member classes in one giant file (as in a JavaScript module),
+ we list the module's classes in the `@NgModule.declarations` list.
+
+ 1. An Angular module can only export the [_declarable classes_](#q-declarables)
+ it owns or imports from other modules.
+ It doesn't declare or export any other kind of class.
+
+ The Angular Module is also special in another way.
+ Unlike JavaScript modules, an Angular module can extend the _entire_ application with services
+ by adding providers to the `@NgModule.providers` list.
+
+.alert.is-important
+ :marked
+ The provided services do not belong to the module nor are they scoped to the declared classes.
+ They are available _everywhere_.
+
+:marked
+ Here's an _Angular Module_ class with imports, exports, and declarations.
++makeExample('ngmodule/ts/app/contact/contact.module.2.ts', 'class')(format=".")
+:marked
+ Of course we use _JavaScript_ modules to write _Angular_ modules as seen in the complete `contact.module.ts` file:
++makeExample('ngmodule/ts/app/contact/contact.module.2.ts', '', 'app/contact/contact.module.ts')(format=".")
+
.l-hr
a#q-template-reference
@@ -1611,41 +2125,3 @@ a#q-angular-compiler
`@NgModule` metadata tells the _Angular Compiler_ what components to compile for this module and
how to link this module with other modules.
-
-.l-hr
-
-a#q-ng-vs-js-modules
-.l-main-section
-:marked
- ### What's the difference between Angular and JavaScript Modules?
-
- Angular and JavaScript are two different yet complementary module systems.
-
- In modern JavaScript, [every file is a _module_](http://exploringjs.com/es6/ch_modules.html).
- Within each file we write an `export` statement to make parts of the module public:
-
-code-example(format='.').
- export class AppComponent { ... }
-
-:marked
- Then we `import` a part in another module:
-
-code-example(format='.').
- import { AppComponent } from './app.component';
-
-:marked
- This kind of modularity is a feature of the _JavaScript language_.
-
- An _Angular Module_ is a feature of _Angular_ itself.
- It describes entire blocks of the application to the [Angular Compiler](#q-angular-compiler).
-
- The _Angular Module_ also has `imports` and `exports` and they serve a similar purpose.
- But it is has other capabilities that are specific to Angular.
- For example, it _declares_ the components, directives, and pipes that belong to the module in a `declarations` list.
-
- Here's an _Angular Module_ class with imports, exports, and declarations.
-+makeExample('ngmodule/ts/app/contact/contact.module.2.ts', 'class')(format=".")
-:marked
- Of course we use _JavaScript_ modules to write _Angular_ modules as seen in the complete `contact.module.ts` file:
-+makeExample('ngmodule/ts/app/contact/contact.module.2.ts', '', 'app/contact/contact.module.ts')(format=".")
-:marked