`,
- styleUrls: ['app/app.component.css'],
- directives: [ROUTER_DIRECTIVES],
- providers: [
- HeroService,
- ]
+ styleUrls: ['app/app.component.css']
})
export class AppComponent {
title = 'Tour of Heroes';
diff --git a/public/docs/_examples/toh-6/ts/app/app.module.1.ts b/public/docs/_examples/toh-6/ts/app/app.module.1.ts
new file mode 100644
index 0000000000..6924d5a390
--- /dev/null
+++ b/public/docs/_examples/toh-6/ts/app/app.module.1.ts
@@ -0,0 +1,44 @@
+// #docplaster
+// #docregion
+import { NgModule } from '@angular/core';
+import { BrowserModule } from '@angular/platform-browser';
+import { FormsModule } from '@angular/forms';
+
+// Imports for loading & configuring the in-memory web api
+import { HttpModule, XHRBackend } from '@angular/http';
+
+import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api';
+import { InMemoryDataService } from './in-memory-data.service';
+
+import { AppComponent } from './app.component';
+import { routing } from './app.routing';
+
+import { HeroesComponent } from './heroes.component';
+import { DashboardComponent } from './dashboard.component';
+import { HeroDetailComponent } from './hero-detail.component';
+
+import { HeroService } from './hero.service';
+
+@NgModule({
+ imports: [
+ BrowserModule,
+ FormsModule,
+ routing,
+ HttpModule
+ ],
+ declarations: [
+ AppComponent,
+ HeroesComponent,
+ DashboardComponent,
+ HeroDetailComponent
+ ],
+ providers: [
+ HeroService,
+ { provide: XHRBackend, useClass: InMemoryBackendService }, // in-mem server
+ { provide: SEED_DATA, useClass: InMemoryDataService } // in-mem server data
+ ],
+ bootstrap: [ AppComponent ]
+})
+export class AppModule {
+}
+// #enddocregion final
diff --git a/public/docs/_examples/toh-6/ts/app/app.module.2.ts b/public/docs/_examples/toh-6/ts/app/app.module.2.ts
new file mode 100644
index 0000000000..2ec598cd0b
--- /dev/null
+++ b/public/docs/_examples/toh-6/ts/app/app.module.2.ts
@@ -0,0 +1,44 @@
+// #docplaster
+// #docregion
+import { NgModule } from '@angular/core';
+import { BrowserModule } from '@angular/platform-browser';
+import { FormsModule } from '@angular/forms';
+import { HttpModule } from '@angular/http';
+
+import { AppComponent } from './app.component';
+import { routing } from './app.routing';
+
+import { HeroesComponent } from './heroes.component';
+import { DashboardComponent } from './dashboard.component';
+import { HeroDetailComponent } from './hero-detail.component';
+// #docregion hero-search-declaration
+import { HeroSearchComponent } from './hero-search.component';
+// #enddocregion hero-search-declaration
+
+import { HeroService } from './hero.service';
+
+@NgModule({
+ imports: [
+ BrowserModule,
+ FormsModule,
+ routing,
+ HttpModule
+ ],
+// #docregion hero-search-declaration
+
+ declarations: [
+ AppComponent,
+ HeroesComponent,
+ DashboardComponent,
+ HeroDetailComponent,
+ HeroSearchComponent
+ ],
+// #enddocregion hero-search-declaration
+ providers: [
+ HeroService
+ ],
+ bootstrap: [ AppComponent ]
+})
+export class AppModule {
+}
+// #enddocregion
diff --git a/public/docs/_examples/toh-6/ts/app/app.module.ts b/public/docs/_examples/toh-6/ts/app/app.module.ts
new file mode 100644
index 0000000000..0beff178e0
--- /dev/null
+++ b/public/docs/_examples/toh-6/ts/app/app.module.ts
@@ -0,0 +1,45 @@
+// #docregion
+import { NgModule } from '@angular/core';
+import { BrowserModule } from '@angular/platform-browser';
+import { FormsModule } from '@angular/forms';
+
+// Imports for loading & configuring the in-memory web api
+import { HttpModule, XHRBackend } from '@angular/http';
+
+import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api';
+import { InMemoryDataService } from './in-memory-data.service';
+
+import { AppComponent } from './app.component';
+import { routing } from './app.routing';
+
+import { HeroesComponent } from './heroes.component';
+import { DashboardComponent } from './dashboard.component';
+import { HeroDetailComponent } from './hero-detail.component';
+import { HeroSearchComponent } from './hero-search.component';
+
+import { HeroService } from './hero.service';
+
+@NgModule({
+ imports: [
+ BrowserModule,
+ FormsModule,
+ routing,
+ HttpModule
+ ],
+ declarations: [
+ AppComponent,
+ HeroesComponent,
+ DashboardComponent,
+ HeroDetailComponent,
+ HeroSearchComponent
+ ],
+ providers: [
+ HeroService,
+ { provide: XHRBackend, useClass: InMemoryBackendService }, // in-mem server
+ { provide: SEED_DATA, useClass: InMemoryDataService } // in-mem server data
+ ],
+ bootstrap: [ AppComponent ]
+})
+export class AppModule {
+}
+// #enddocregion
diff --git a/public/docs/_examples/toh-6/ts/app/app.routes.ts b/public/docs/_examples/toh-6/ts/app/app.routing.ts
similarity index 56%
rename from public/docs/_examples/toh-6/ts/app/app.routes.ts
rename to public/docs/_examples/toh-6/ts/app/app.routing.ts
index e143b2a3bf..c5753a4ee9 100644
--- a/public/docs/_examples/toh-6/ts/app/app.routes.ts
+++ b/public/docs/_examples/toh-6/ts/app/app.routing.ts
@@ -1,11 +1,11 @@
// #docregion
-import { provideRouter, RouterConfig } from '@angular/router';
+import { Routes, RouterModule } from '@angular/router';
-import { DashboardComponent } from './dashboard.component';
-import { HeroesComponent } from './heroes.component';
+import { DashboardComponent } from './dashboard.component';
+import { HeroesComponent } from './heroes.component';
import { HeroDetailComponent } from './hero-detail.component';
-const routes: RouterConfig = [
+const appRoutes: Routes = [
{
path: '',
redirectTo: '/dashboard',
@@ -25,6 +25,4 @@ const routes: RouterConfig = [
}
];
-export const appRouterProviders = [
- provideRouter(routes)
-];
+export const routing = RouterModule.forRoot(appRoutes);
diff --git a/public/docs/_examples/toh-6/ts/app/dashboard.component.ts b/public/docs/_examples/toh-6/ts/app/dashboard.component.ts
index 41b4de58df..4a90a4d6bf 100644
--- a/public/docs/_examples/toh-6/ts/app/dashboard.component.ts
+++ b/public/docs/_examples/toh-6/ts/app/dashboard.component.ts
@@ -1,16 +1,14 @@
// #docregion , search
import { Component, OnInit } from '@angular/core';
-import { Router } from '@angular/router';
+import { Router } from '@angular/router';
import { Hero } from './hero';
import { HeroService } from './hero.service';
-import { HeroSearchComponent } from './hero-search.component';
@Component({
selector: 'my-dashboard',
templateUrl: 'app/dashboard.component.html',
- styleUrls: ['app/dashboard.component.css'],
- directives: [HeroSearchComponent]
+ styleUrls: ['app/dashboard.component.css']
})
// #enddocregion search
export class DashboardComponent implements OnInit {
diff --git a/public/docs/_examples/toh-6/ts/app/hero-detail.component.ts b/public/docs/_examples/toh-6/ts/app/hero-detail.component.ts
index 85d722999e..062917401e 100644
--- a/public/docs/_examples/toh-6/ts/app/hero-detail.component.ts
+++ b/public/docs/_examples/toh-6/ts/app/hero-detail.component.ts
@@ -1,9 +1,9 @@
// #docplaster
// #docregion, variables-imports
-import { Component, EventEmitter, Input, OnInit, OnDestroy, Output } from '@angular/core';
+import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
// #enddocregion variables-imports
-import { ActivatedRoute } from '@angular/router';
+import { ActivatedRoute, Params } from '@angular/router';
import { Hero } from './hero';
import { HeroService } from './hero.service';
@@ -14,11 +14,10 @@ import { HeroService } from './hero.service';
styleUrls: ['app/hero-detail.component.css']
})
// #docregion variables-imports
-export class HeroDetailComponent implements OnInit, OnDestroy {
+export class HeroDetailComponent implements OnInit {
@Input() hero: Hero;
@Output() close = new EventEmitter();
error: any;
- sub: any;
navigated = false; // true if navigated here
// #enddocregion variables-imports
@@ -29,7 +28,7 @@ export class HeroDetailComponent implements OnInit, OnDestroy {
// #docregion ngOnInit
ngOnInit() {
- this.sub = this.route.params.subscribe(params => {
+ this.route.params.forEach((params: Params) => {
if (params['id'] !== undefined) {
let id = +params['id'];
this.navigated = true;
@@ -43,10 +42,6 @@ export class HeroDetailComponent implements OnInit, OnDestroy {
}
// #enddocregion ngOnInit
- ngOnDestroy() {
- this.sub.unsubscribe();
- }
-
// #docregion save
save() {
this.heroService
diff --git a/public/docs/_examples/toh-6/ts/app/heroes.component.ts b/public/docs/_examples/toh-6/ts/app/heroes.component.ts
index 3bf618f5bd..e5c5ab1c49 100644
--- a/public/docs/_examples/toh-6/ts/app/heroes.component.ts
+++ b/public/docs/_examples/toh-6/ts/app/heroes.component.ts
@@ -5,13 +5,11 @@ import { Router } from '@angular/router';
import { Hero } from './hero';
import { HeroService } from './hero.service';
// #docregion hero-detail-component
-import { HeroDetailComponent } from './hero-detail.component';
@Component({
selector: 'my-heroes',
templateUrl: 'app/heroes.component.html',
- styleUrls: ['app/heroes.component.css'],
- directives: [HeroDetailComponent]
+ styleUrls: ['app/heroes.component.css']
})
// #enddocregion hero-detail-component
export class HeroesComponent implements OnInit {
diff --git a/public/docs/_examples/toh-6/ts/app/main.ts b/public/docs/_examples/toh-6/ts/app/main.ts
index bda66d0377..091a7d82a7 100644
--- a/public/docs/_examples/toh-6/ts/app/main.ts
+++ b/public/docs/_examples/toh-6/ts/app/main.ts
@@ -1,33 +1,6 @@
-// #docplaster
-// #docregion final
-// Imports for loading & configuring the in-memory web api
-import { XHRBackend } from '@angular/http';
+// #docregion
+// main entry point
+import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
+import { AppModule } from './app.module';
-import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api';
-import { InMemoryDataService } from './in-memory-data.service';
-
-// The usual bootstrapping imports
-// #docregion v1
-import { bootstrap } from '@angular/platform-browser-dynamic';
-import { HTTP_PROVIDERS } from '@angular/http';
-
-import { AppComponent } from './app.component';
-import { appRouterProviders } from './app.routes';
-
-// #enddocregion v1, final
-/*
-// #docregion v1
-bootstrap(AppComponent, [
- appRouterProviders,
- HTTP_PROVIDERS
-]);
-// #enddocregion v1
-*/
-// #docregion final
-bootstrap(AppComponent, [
- appRouterProviders,
- HTTP_PROVIDERS,
- { provide: XHRBackend, useClass: InMemoryBackendService }, // in-mem server
- { provide: SEED_DATA, useClass: InMemoryDataService } // in-mem server data
-]);
-// #enddocregion final
+platformBrowserDynamic().bootstrapModule(AppModule);
diff --git a/public/docs/_examples/typings.json b/public/docs/_examples/typings.json
index a4bf5572aa..3d826df25a 100644
--- a/public/docs/_examples/typings.json
+++ b/public/docs/_examples/typings.json
@@ -2,6 +2,6 @@
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160602141332",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
- "node": "registry:dt/node#6.0.0+20160720070758"
+ "node": "registry:dt/node#6.0.0+20160807145350"
}
}
diff --git a/public/docs/_examples/upgrade-adapter/e2e-spec.ts b/public/docs/_examples/upgrade-adapter/e2e-spec.ts.disabled
similarity index 100%
rename from public/docs/_examples/upgrade-adapter/e2e-spec.ts
rename to public/docs/_examples/upgrade-adapter/e2e-spec.ts.disabled
diff --git a/public/docs/_examples/upgrade-phonecat-2-hybrid/e2e-spec.ts b/public/docs/_examples/upgrade-phonecat-2-hybrid/e2e-spec.ts.disabled
similarity index 100%
rename from public/docs/_examples/upgrade-phonecat-2-hybrid/e2e-spec.ts
rename to public/docs/_examples/upgrade-phonecat-2-hybrid/e2e-spec.ts.disabled
diff --git a/public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/core/checkmark/checkmark.pipe.spec.ts b/public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/core/checkmark/checkmark.pipe.spec.ts.disabled
similarity index 92%
rename from public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/core/checkmark/checkmark.pipe.spec.ts
rename to public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/core/checkmark/checkmark.pipe.spec.ts.disabled
index 5b9ad15f32..3881a30e4d 100644
--- a/public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/core/checkmark/checkmark.pipe.spec.ts
+++ b/public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/core/checkmark/checkmark.pipe.spec.ts.disabled
@@ -1,10 +1,7 @@
// #docregion
import {
- describe,
beforeEachProviders,
- it,
- inject,
- expect
+ inject
} from '@angular/core/testing';
import { CheckmarkPipe } from './checkmark.pipe';
diff --git a/public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/core/phone/phone.service.spec.ts b/public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/core/phone/phone.service.spec.ts.disabled
similarity index 100%
rename from public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/core/phone/phone.service.spec.ts
rename to public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/core/phone/phone.service.spec.ts.disabled
diff --git a/public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/phone-detail/phone-detail.component.spec.ts b/public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/phone-detail/phone-detail.component.spec.ts.disabled
similarity index 100%
rename from public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/phone-detail/phone-detail.component.spec.ts
rename to public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/phone-detail/phone-detail.component.spec.ts.disabled
diff --git a/public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/phone-list/phone-list.component.spec.ts b/public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/phone-list/phone-list.component.spec.ts.disabled
similarity index 100%
rename from public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/phone-list/phone-list.component.spec.ts
rename to public/docs/_examples/upgrade-phonecat-2-hybrid/ts/app/phone-list/phone-list.component.spec.ts.disabled
diff --git a/public/docs/_examples/upgrade-phonecat-3-final/e2e-spec.ts b/public/docs/_examples/upgrade-phonecat-3-final/e2e-spec.ts.disabled
similarity index 100%
rename from public/docs/_examples/upgrade-phonecat-3-final/e2e-spec.ts
rename to public/docs/_examples/upgrade-phonecat-3-final/e2e-spec.ts.disabled
diff --git a/public/docs/_examples/upgrade-phonecat-3-final/ts/app/core/checkmark/checkmark.pipe.spec.ts b/public/docs/_examples/upgrade-phonecat-3-final/ts/app/core/checkmark/checkmark.pipe.spec.ts.disabled
similarity index 100%
rename from public/docs/_examples/upgrade-phonecat-3-final/ts/app/core/checkmark/checkmark.pipe.spec.ts
rename to public/docs/_examples/upgrade-phonecat-3-final/ts/app/core/checkmark/checkmark.pipe.spec.ts.disabled
diff --git a/public/docs/_examples/upgrade-phonecat-3-final/ts/app/core/phone/phone.service.spec.ts b/public/docs/_examples/upgrade-phonecat-3-final/ts/app/core/phone/phone.service.spec.ts.disabled
similarity index 100%
rename from public/docs/_examples/upgrade-phonecat-3-final/ts/app/core/phone/phone.service.spec.ts
rename to public/docs/_examples/upgrade-phonecat-3-final/ts/app/core/phone/phone.service.spec.ts.disabled
diff --git a/public/docs/_examples/upgrade-phonecat-3-final/ts/app/main.ts b/public/docs/_examples/upgrade-phonecat-3-final/ts/app/main.ts
index f59e9c7afd..4db648092b 100644
--- a/public/docs/_examples/upgrade-phonecat-3-final/ts/app/main.ts
+++ b/public/docs/_examples/upgrade-phonecat-3-final/ts/app/main.ts
@@ -6,6 +6,7 @@ import {
APP_BASE_HREF
} from '@angular/common';
import { bootstrap } from '@angular/platform-browser-dynamic';
+import { FormsModule } from '@angular/forms';
import { HTTP_PROVIDERS } from '@angular/http';
import { ROUTER_PROVIDERS } from '@angular/router-deprecated';
import { Phone } from './core/phone/phone.service';
@@ -13,11 +14,14 @@ import { AppComponent } from './app.component';
// #enddocregion imports
// #docregion bootstrap
-bootstrap(AppComponent, [
- HTTP_PROVIDERS,
- ROUTER_PROVIDERS,
- { provide: APP_BASE_HREF, useValue: '!' },
- { provide: LocationStrategy, useClass: HashLocationStrategy },
- Phone
-]);
+bootstrap(AppComponent, {
+ imports: [FormsModule],
+ providers: [
+ HTTP_PROVIDERS,
+ ROUTER_PROVIDERS,
+ { provide: APP_BASE_HREF, useValue: '!' },
+ { provide: LocationStrategy, useClass: HashLocationStrategy },
+ Phone
+ ]
+});
// #enddocregion bootstrap
diff --git a/public/docs/_examples/upgrade-phonecat-3-final/ts/app/phone-detail/phone-detail.component.spec.ts b/public/docs/_examples/upgrade-phonecat-3-final/ts/app/phone-detail/phone-detail.component.spec.ts.disabled
similarity index 100%
rename from public/docs/_examples/upgrade-phonecat-3-final/ts/app/phone-detail/phone-detail.component.spec.ts
rename to public/docs/_examples/upgrade-phonecat-3-final/ts/app/phone-detail/phone-detail.component.spec.ts.disabled
diff --git a/public/docs/_examples/upgrade-phonecat-3-final/ts/app/phone-list/phone-list.component.spec.ts b/public/docs/_examples/upgrade-phonecat-3-final/ts/app/phone-list/phone-list.component.spec.ts.disabled
similarity index 100%
rename from public/docs/_examples/upgrade-phonecat-3-final/ts/app/phone-list/phone-list.component.spec.ts
rename to public/docs/_examples/upgrade-phonecat-3-final/ts/app/phone-list/phone-list.component.spec.ts.disabled
diff --git a/public/docs/_examples/user-input/ts/app/app.component.ts b/public/docs/_examples/user-input/ts/app/app.component.ts
index 330d84b5a1..35be5f232d 100644
--- a/public/docs/_examples/user-input/ts/app/app.component.ts
+++ b/public/docs/_examples/user-input/ts/app/app.component.ts
@@ -1,26 +1,8 @@
// #docregion
import { Component } from '@angular/core';
-import { ClickMeComponent } from './click-me.component';
-import { ClickMe2Component } from './click-me2.component';
-
-import { LoopbackComponent } from './loop-back.component';
-
-import { KeyUpComponent_v1,
- KeyUpComponent_v2,
- KeyUpComponent_v3,
- KeyUpComponent_v4 } from './keyup.components';
-
-import { LittleTourComponent } from './little-tour.component';
-
@Component({
selector: 'my-app',
- templateUrl: 'app/app.component.html',
- directives: [
- ClickMeComponent, ClickMe2Component,
- LoopbackComponent,
- KeyUpComponent_v1, KeyUpComponent_v2, KeyUpComponent_v3, KeyUpComponent_v4,
- LittleTourComponent
- ]
+ templateUrl: 'app/app.component.html'
})
export class AppComponent { }
diff --git a/public/docs/_examples/user-input/ts/app/app.module.ts b/public/docs/_examples/user-input/ts/app/app.module.ts
new file mode 100644
index 0000000000..41f13f9f11
--- /dev/null
+++ b/public/docs/_examples/user-input/ts/app/app.module.ts
@@ -0,0 +1,37 @@
+import { NgModule } from '@angular/core';
+import { BrowserModule } from '@angular/platform-browser';
+
+import { AppComponent } from './app.component';
+import { ClickMeComponent } from './click-me.component';
+import { ClickMe2Component } from './click-me2.component';
+import {
+ KeyUpComponent_v1,
+ KeyUpComponent_v2,
+ KeyUpComponent_v3,
+ KeyUpComponent_v4
+} from './keyup.components';
+import { LittleTourComponent } from './little-tour.component';
+import { LoopbackComponent } from './loop-back.component';
+
+
+@NgModule({
+ imports: [
+ BrowserModule
+ ],
+ declarations: [
+ AppComponent,
+ ClickMeComponent,
+ ClickMe2Component,
+ KeyUpComponent_v1,
+ KeyUpComponent_v2,
+ KeyUpComponent_v3,
+ KeyUpComponent_v4,
+ LittleTourComponent,
+ LoopbackComponent
+ ],
+ providers: [
+
+ ],
+ bootstrap: [ AppComponent ]
+})
+export class AppModule { }
diff --git a/public/docs/_examples/user-input/ts/app/main.ts b/public/docs/_examples/user-input/ts/app/main.ts
index 42dbeb9f7d..6af7a5b2ae 100644
--- a/public/docs/_examples/user-input/ts/app/main.ts
+++ b/public/docs/_examples/user-input/ts/app/main.ts
@@ -1,5 +1,5 @@
-import { bootstrap } from '@angular/platform-browser-dynamic';
+import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
-import { AppComponent } from './app.component';
+import { AppModule } from './app.module';
-bootstrap(AppComponent);
+platformBrowserDynamic().bootstrapModule(AppModule);
diff --git a/public/docs/_examples/webpack/e2e-spec.ts b/public/docs/_examples/webpack/e2e-spec.ts.disabled
similarity index 100%
rename from public/docs/_examples/webpack/e2e-spec.ts
rename to public/docs/_examples/webpack/e2e-spec.ts.disabled
diff --git a/public/docs/_examples/webpack/ts/package.webpack.json b/public/docs/_examples/webpack/ts/package.webpack.json
index e383ba3355..4b3dc3e15d 100644
--- a/public/docs/_examples/webpack/ts/package.webpack.json
+++ b/public/docs/_examples/webpack/ts/package.webpack.json
@@ -10,14 +10,14 @@
},
"license": "MIT",
"dependencies": {
- "@angular/common": "2.0.0-rc.4",
- "@angular/compiler": "2.0.0-rc.4",
- "@angular/core": "2.0.0-rc.4",
- "@angular/forms": "0.2.0",
- "@angular/http": "2.0.0-rc.4",
- "@angular/platform-browser": "2.0.0-rc.4",
- "@angular/platform-browser-dynamic": "2.0.0-rc.4",
- "@angular/router": "3.0.0-beta.1",
+ "@angular/common": "2.0.0-rc.5",
+ "@angular/compiler": "2.0.0-rc.5",
+ "@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",
"core-js": "^2.4.0",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.6",
diff --git a/public/docs/_examples/webpack/ts/src/app/app.component.spec.ts b/public/docs/_examples/webpack/ts/src/app/app.component.spec.ts
index c2e85fd099..d7d0696aef 100644
--- a/public/docs/_examples/webpack/ts/src/app/app.component.spec.ts
+++ b/public/docs/_examples/webpack/ts/src/app/app.component.spec.ts
@@ -1,18 +1,17 @@
// #docregion
import {
- it,
+ addProviders,
inject,
- describe,
- beforeEachProviders,
- expect
} from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('App', () => {
- beforeEachProviders(() => [
- AppComponent
- ]);
+ beforeEach(() => {
+ addProviders([
+ AppComponent
+ ]);
+ });
it ('should work', inject([AppComponent], (app: AppComponent) => {
// Add real test here
diff --git a/public/docs/_examples/webpack/ts/src/app/app.module.ts b/public/docs/_examples/webpack/ts/src/app/app.module.ts
new file mode 100644
index 0000000000..362f3401fa
--- /dev/null
+++ b/public/docs/_examples/webpack/ts/src/app/app.module.ts
@@ -0,0 +1,16 @@
+// #docregion
+import { NgModule } from '@angular/core';
+import { BrowserModule } from '@angular/platform-browser';
+
+import { AppComponent } from './app.component';
+
+@NgModule({
+ imports: [
+ BrowserModule
+ ],
+ declarations: [
+ AppComponent
+ ],
+ bootstrap: [ AppComponent ]
+})
+export class AppModule { }
diff --git a/public/docs/_examples/webpack/ts/src/main.ts b/public/docs/_examples/webpack/ts/src/main.ts
index 8ea0ea84ce..0057db95ab 100644
--- a/public/docs/_examples/webpack/ts/src/main.ts
+++ b/public/docs/_examples/webpack/ts/src/main.ts
@@ -1,8 +1,8 @@
// #docregion
-import { bootstrap } from '@angular/platform-browser-dynamic';
+import { browserDynamicPlatform } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
-import { AppComponent } from './app/app.component';
+import { AppModule } from './app/app.module';
// #docregion enable-prod
if (process.env.ENV === 'production') {
@@ -10,5 +10,5 @@ if (process.env.ENV === 'production') {
}
// #enddocregion enable-prod
-bootstrap(AppComponent, []);
+browserDynamicPlatform().bootstrapModule(AppModule);
// #enddocregion
diff --git a/public/docs/_examples/webpack/ts/typings.1.json b/public/docs/_examples/webpack/ts/typings.1.json
index 3385926d1f..3d826df25a 100644
--- a/public/docs/_examples/webpack/ts/typings.1.json
+++ b/public/docs/_examples/webpack/ts/typings.1.json
@@ -2,6 +2,6 @@
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160602141332",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
- "node": "registry:dt/node#6.0.0+20160621231320"
+ "node": "registry:dt/node#6.0.0+20160807145350"
}
}
diff --git a/public/docs/js/latest/_data.json b/public/docs/js/latest/_data.json
index 7d5ed7b13a..7bbc458b55 100644
--- a/public/docs/js/latest/_data.json
+++ b/public/docs/js/latest/_data.json
@@ -3,7 +3,7 @@
"icon": "home",
"title": "Angular Docs",
"menuTitle": "Docs Home",
- "banner": "Welcome to Angular in JavaScript! The current Angular 2 release is rc.4. Please consult the Change Log about recent enhancements, fixes, and breaking changes."
+ "banner": "Welcome to Angular in JavaScript! The current Angular 2 release is rc.5. Please consult the Change Log about recent enhancements, fixes, and breaking changes."
},
"quickstart": {
diff --git a/public/docs/js/latest/guide/_data.json b/public/docs/js/latest/guide/_data.json
index 1e0d9aa221..250d244eb4 100644
--- a/public/docs/js/latest/guide/_data.json
+++ b/public/docs/js/latest/guide/_data.json
@@ -29,7 +29,7 @@
"basics": true
},
- "forms-deprecated": {
+ "forms": {
"title": "Forms",
"intro": "A form creates a cohesive, effective, and compelling data entry experience. An Angular form coordinates a set of data-bound user controls, tracks changes, validates input, and presents errors.",
"nextable": true,
diff --git a/public/docs/js/latest/guide/forms-deprecated.jade b/public/docs/js/latest/guide/forms-deprecated.jade
index 5a963272c8..b825bf6f2c 100644
--- a/public/docs/js/latest/guide/forms-deprecated.jade
+++ b/public/docs/js/latest/guide/forms-deprecated.jade
@@ -2,7 +2,7 @@ include ../_util-fns
.alert.is-important
:marked
- This guide is using the deprecated forms API.
+ This guide is using the deprecated forms API, which is disabled as of RC5, thus this sample only works up to RC4.
We have created a new version using the new API here.
diff --git a/public/docs/js/latest/quickstart.jade b/public/docs/js/latest/quickstart.jade
index 315d687414..045eb758ab 100644
--- a/public/docs/js/latest/quickstart.jade
+++ b/public/docs/js/latest/quickstart.jade
@@ -29,11 +29,12 @@ figure.image-display
.file app
.children
.file app.component.js
+ .file app.module.js
.file main.js
.file index.html
.file styles.css
:marked
- Functionally, it's an `index.html`, `styles.css` and two JavaScript files in an `app/` folder.
+ Functionally, it's an `index.html`, `styles.css` and three JavaScript files in an `app/` folder.
We can handle that!
Of course we won't build many apps that only run in plunker.
@@ -41,6 +42,7 @@ figure.image-display
1. Set up our development environment
1. Write the Angular root component for our app
+ 1. Add an Angular Module
1. Bootstrap it to take control of the main web page
1. Write the main page (`index.html`)
1. Add some CSS (`styles.css`)
@@ -124,7 +126,7 @@ code-example(format="").
'(component schema)')(format=".")
:marked
- The **`Component`** method takes a configuration object with two
+ The **`Component`** method takes a configuration object with three
properties. The **`Class`** method is where we implement the component itself,
giving it properties and methods that bind to the view and whatever
behavior is appropriate for this part of the UI.
@@ -167,7 +169,7 @@ code-example(format="").
provided by another module, we get it from the `app` object.
When another module needs to refer to `AppComponent`, it gets it from the `app.AppComponent` like this:
-+makeExample('quickstart/js/app/main.js', 'import','app/main.js (import)')(format=".")
++makeExample('quickstart/js/app/app.module.js', 'import', 'app/app.module.js (import)')(format=".")
:marked
Angular is also modular. It is a collection of library modules.
@@ -210,22 +212,36 @@ code-example(format="").
Now we need something to tell Angular to load this component.
+ ### Add an NgModule
+
+ Angular apps are composed of [Angular Modules](guide/ngmodules.html) that
+ snuggly contain all our components and everything else we need for our app.
+
+ Create the `app/app.module.ts` file with the following content:
+
++makeExample('quickstart/js/app/app.module.js', null, 'app/app.module.js')
+
+.l-sub-section
+ :marked
+ Read more about the `NgModule` configuration in the [appendix below](#ngmodule).
+
+:marked
### Bootstrap it!
-
+
Add a new file , `main.js`, to the `app/` folder as follows:
+makeExample('quickstart/js/app/main.js', null, 'app/main.js')(format=".")
:marked
We need two things to launch the application:
- 1. Angular's browser `bootstrap` function
- 1. The application root component that we just wrote.
+ 1. Angular's `platformBrowserDynamic().bootstrapModule` function
+ 1. The application root module that we just wrote.
We have them both in our 'namespaces'.
- Then we call `bootstrap`, passing in the **root component type**, `AppComponent`.
+ Then we call `bootstrapModule`, passing in the **root app module**, `AppModule`.
.l-sub-section
:marked
- Learn why we need `bootstrap` from `ng.platformBrowserDynamic`
- and why we create a separate *main.js* file in the [appendix below](#main).
+ Learn why we need `bootstrapModule` from `ng.platformBrowserDynamic`
+ and why we create a separate js files in the [appendix below](#main).
:marked
We've asked Angular to launch the app in a browser with our component at the root.
Where will Angular put it?
@@ -250,13 +266,14 @@ code-example(format="").
1. We load the JavaScript libraries we need; learn about them [below](#libraries).
- 2. We load our JavaScript files, paying attention to their order (`main.js` needs `app.component.js` to be there first).
+ 2. We load our JavaScript files, paying attention to their order (`main.js` needs `app.module.js` to be there first, and `app.module.js` needs `app.component.js`).
3. We add the `` tag in the ``. **This is where our app lives!**
- When Angular calls the `bootstrap` function in `main.js`, it reads the `AppComponent`
- metadata, finds the `my-app` selector, locates an element tag named `my-app`,
- and loads our application between those tags.
+ When Angular calls the `bootstrapModule` function in `main.js`,
+ it reads the `AppModule` metadata, sees that `AppComponent` is the bootstrap component,
+ finds the `my-app` selector, locates an element tag named `my-app`,
+ and renders our application's view between those tags.
:marked
### Add some style
@@ -314,6 +331,7 @@ figure.image-display
.file app
.children
.file app.component.js
+ .file app.module.js
.file main.js
.file index.html
.file package.json
@@ -322,12 +340,18 @@ figure.image-display
And here are the files:
+makeTabs(`
quickstart/js/app/app.component.js,
+ quickstart/js/app/app.module.js,
quickstart/js/app/main.js,
quickstart/js/index.html,
quickstart/js/package.1.json,
quickstart/js/styles.1.css
`,null,
- `app/app.component.js, app/main.js, index.html, package.json, styles.css`)
+ `app/app.component.js,
+ app/app.module.js,
+ app/main.js,
+ index.html,
+ package.json,
+ styles.css`)
:marked
.l-main-section
@@ -448,13 +472,32 @@ code-example(format="").
Just make sure there are no `npm ERR!` messages at the very end of `npm install`.
+.l-main-section
+:marked
+
+ ### Appendix: ***NgModule***
+ The `NgModule` decorator is listing:
+
+ 1. What other Angular Modules ours uses
+ 1. Which components and directives we declare in our components
+ 1. The component to bootstrap at the start
+
+ We import our lone `app.AppComponent` and add it to both `declaration` and `bootstrap` array.
+
+ Notice that we also add `ng.platformBrowser.BrowserModule` to the `imports` array.
+ This is the Angular Module that contains all the needed Angular bits and pieces to run our app in the browser.
+
+ Angular itself is split into separate Angular Modules so we only need to import the ones we really use.
+
+ One of the most common ones is `FormsModule`, and soon we'll also see `RouterModule` and `HttpModule`.
+
.l-main-section
:marked
### Appendix: ***main.js***
#### Bootstrapping is platform-specific
- We use the `bootstrap` function from `ng.platformBrowserDynamic`,
+ We use the `platformBrowserDynamic().bootstrapModule` function from `ng.platformBrowserDynamic`,
not `ng.core`. There's a good reason.
We only call "core" those capabilities that are the same across all platform targets.
@@ -469,11 +512,11 @@ code-example(format="").
These targets require a different kind of bootstrap function that we'd import from a different library.
- #### Why do we create a separate ***main.js*** file?
+ #### Why do we create a separate ***main.js***, ***app.module.js*** and ***app.component.js*** files?
The *main.js* file is tiny. This is just a QuickStart.
- We could have folded its few lines into the `app.component.js` file
- and spared ourselves some complexity.
+ We could have folded its few lines into the `app.module.js` file, and that one into
+ `app.component.js` and spared ourselves some complexity.
We didn't for what we believe to be good reasons:
1. Doing it right is easy
@@ -485,7 +528,7 @@ code-example(format="").
#### It's easy
Sure it's an extra step and an extra file. How hard is that in the scheme of things?
- We'll see that a separate `main.js` is beneficial for *most* apps
+ We'll see that a separate `main.js` and `app.module.js` is beneficial for *most* apps
even if it isn't critical for the QuickStart.
Let's develop good habits now while the cost is low.
@@ -493,32 +536,33 @@ code-example(format="").
We should be thinking about testability from the beginning
even if we know we'll never test the QuickStart.
- It is difficult to unit test a component when there is a call to `bootstrap` in the same file.
+ It is difficult to unit test a component when there is a call to `bootstrapModule` in the same file.
As soon as we load the component file to test the component,
- the `bootstrap` function tries to load the application in the browser.
+ the `bootstrapModule` function tries to load the application in the browser.
It throws an error because we're not expecting to run the entire application,
just test the component.
- Relocating the `bootstrap` function to `main.js` eliminates this spurious error
+ Relocating the `bootstrapModule` function to `main.js` eliminates this spurious error
and leaves us with a clean component module file.
#### Reusability
We refactor, rename, and relocate files as our application evolves.
- We can't do any of those things while the file calls `bootstrap`.
+ We can't do any of those things while the file calls `bootstrapModule`.
we can't move it.
We can't reuse the component in another application.
We can't pre-render the component on the server for better performance.
#### Separation of concerns
- A component's responsibility is to present and manage a view.
+ A component's responsibility is to present and manage a view, and a NgModule's
+ reponsibility is to define the application context.
- Launching the application has nothing to do with view management.
+ Launching the application has nothing to do with any of these.
That's a separate concern. The friction we're encountering in testing and reuse
stems from this unnecessary mix of responsibilities.
#### Import/Export
- While writing a separate `main.js` file we learned an essential Angular skill:
+ While writing a separate `main.js` and `app.module.js` files we learned an essential Angular skill:
how to 'export' from one 'module' and 'import' into another via our simple
namespace abstraction.
We'll do a lot of that as we learn more Angular.
diff --git a/public/docs/ts/latest/_data.json b/public/docs/ts/latest/_data.json
index 735c69c2b2..6f63472d16 100644
--- a/public/docs/ts/latest/_data.json
+++ b/public/docs/ts/latest/_data.json
@@ -3,7 +3,7 @@
"icon": "home",
"title": "Angular Docs",
"menuTitle": "Docs Home",
- "banner": "Welcome to Angular in TypeScript! The current Angular 2 release is rc.4. Please consult the Change Log about recent enhancements, fixes, and breaking changes."
+ "banner": "Welcome to Angular in TypeScript! The current Angular 2 release is rc.5. Please consult the Change Log about recent enhancements, fixes, and breaking changes."
},
"cli-quickstart": {
diff --git a/public/docs/ts/latest/cookbook/_data.json b/public/docs/ts/latest/cookbook/_data.json
index 2607a72898..ecfc0e22d6 100644
--- a/public/docs/ts/latest/cookbook/_data.json
+++ b/public/docs/ts/latest/cookbook/_data.json
@@ -28,14 +28,14 @@
"dynamic-form-deprecated": {
"title": "Dynamic Forms",
- "intro": "Render dynamic forms with NgFormModel"
+ "intro": "Render dynamic forms with NgFormModel",
+ "basics": true,
+ "hide": true
},
"dynamic-form": {
"title": "Dynamic Forms",
- "intro": "Render dynamic forms with FormGroup",
- "basics": true,
- "hide": true
+ "intro": "Render dynamic forms with FormGroup"
},
"set-document-title": {
diff --git a/public/docs/ts/latest/cookbook/a1-a2-quick-reference.jade b/public/docs/ts/latest/cookbook/a1-a2-quick-reference.jade
index 8860d2bfe9..9145c58b1d 100644
--- a/public/docs/ts/latest/cookbook/a1-a2-quick-reference.jade
+++ b/public/docs/ts/latest/cookbook/a1-a2-quick-reference.jade
@@ -16,13 +16,11 @@ a(id="top")
* [Filters/Pipes](#filters-pipes) - built-in *filters*, known as *pipes* in Angular 2
- * [Controllers/Components](#controllers-components) - *controllers* are *components* in Angular 2.
- Also covers modules.
+ * [Modules/Controllers/Components](#controllers-components) - *modules* are *modules* but different
+ and *controllers* are *components* in Angular 2.
* [Style Sheets](#style-sheets) - more options for CSS in Angular 2.
- * [String date pipe](#string-dates) - a tip for displaying string date values.
-
.l-main-section
:marked
## Template Basics
@@ -49,7 +47,7 @@ table(width="100%")
associated with this template.
When using the `controller as` syntax,
- the binding is prefixed with the controller alias (`vm`) because we
+ the binding is prefixed with the controller alias (`vm` or `$ctrl`) because we
have to be specific about the source of the binding.
td
:marked
@@ -131,11 +129,15 @@ table(width="100%")
td
:marked
### Bootstrapping
- +makeExample('cb-a1-a2-quick-reference/ts/app/main.1.ts')(format="." )
+ +makeExample('cb-a1-a2-quick-reference/ts/app/main.ts','','main.ts')(format="." )
+
+ +makeExample('cb-a1-a2-quick-reference/ts/app/app.module.1.ts','','app.module.ts')(format="." )
+
:marked
Angular 2 does not have a bootstrap directive.
- We always launch the app in code by explicitly calling a bootstrap function
- and passing it the name of the application's module (`AppComponent`).
+ We always launch the app in code by explicitly bootstrapping the application's root module (`AppModule`)
+ in `main.ts`
+ and the application's root component (`AppComponent`) in `app.module.ts`.
For more information see [Quick Start](../quickstart.html).
tr(style=top)
@@ -499,7 +501,7 @@ table(width="100%")
### date
+makeExample('cb-a1-a2-quick-reference/ts/app/app.component.html', 'date')(format=".")
:marked
- The Angular 2 `date` pipe is similar. See [note](#string-dates) about string date values.
+ The Angular 2 `date` pipe is similar.
tr(style=top)
td
@@ -604,7 +606,10 @@ table(width="100%")
a(id="controllers-components")
.l-main-section
:marked
- ## Controllers / Components
+ ## Modules / Controllers / Components
+ In both Angular 1 and Angular 2, we use Angular modules to
+ help us organize our application into cohesive blocks of functionality.
+
In Angular 1, we write the code that provides the model and the methods for the view in a **controller**.
In Angular 2, we build a **component**.
@@ -647,15 +652,14 @@ table(width="100%")
of other modules that this module depends upon.
td
:marked
- ### import
- +makeExample('cb-a1-a2-quick-reference/ts/app/movie-list.component.ts', 'import')(format=".")
+ ### Angular modules
+ +makeExample('cb-a1-a2-quick-reference/ts/app/app.module.1.ts')(format=".")
:marked
- Angular 2 does not have its own module system. Instead we use ES 2015 modules.
- ES 2015 modules are file based, so each code file is its own module.
+ Angular 2 modules, defined with the `NgModule` decorator, serve the same purpose:
+ - `imports`: specifies the list of other modules that this module depends upon
+ - `declaration`: keeps track of our components, pipes, and directives.
- We `import` what we need from the module files.
-
- For more information on modules see [Architecture Overview](../guide/architecture.html#module).
+ For more information on modules see [Angular Modules](../guide/ngmodule.html).
tr(style=top)
td
:marked
@@ -773,23 +777,3 @@ table(width="100%")
other parts of the application.
:marked
[Back to top](#top)
-
-a(id="string-dates")
-.l-main-section
-:marked
- ## Appendix: String dates
-
- Currently the Angular 2 `date` pipe does not process string dates such as
- "2015-12-19T00:00:00".
-
- As a work around, subclass the Angular `DatePipe` with a version that can convert strings
- and substitute that pipe in the HTML:
-
-+makeExample('cb-a1-a2-quick-reference/ts/app/date.pipe.ts', 'date-pipe', 'date.pipe.ts')(format=".")
-:marked
- Then import and declare that pipe in the `@Component` metadata `pipes` array:
-:marked
-+makeExample('cb-a1-a2-quick-reference/ts/app/movie-list.component.ts', 'date-pipe')(format=".")
-
-:marked
- [Back to top](#top)
diff --git a/public/docs/ts/latest/cookbook/dependency-injection.jade b/public/docs/ts/latest/cookbook/dependency-injection.jade
index 352ecd3c2b..acfb42c1f5 100644
--- a/public/docs/ts/latest/cookbook/dependency-injection.jade
+++ b/public/docs/ts/latest/cookbook/dependency-injection.jade
@@ -80,7 +80,7 @@ include ../_util-fns
.l-main-section
:marked
## External module configuration
- We can register _certain_ module providers when bootstrapping rather than in the root application component.
+ We can register _certain_ module providers in the `NgModule` rather than in the root application component.
We'd do this when we expect to select or configure external modules that support our application
but (a) aren't conceptually part of the application and (b) that we could change later without
@@ -95,10 +95,10 @@ include ../_util-fns
We'll switch to the real backend in production.
The application shouldn't know or care one way or the other.
- See both examples in the following `main.ts`
- where we list their service providers in an array in the second parameter of the `bootstrap` method.
+ See both examples in the following `app.module.ts`
+ where we list their service providers in the `providers` array of the `NgModule` (AppModule).
-+makeExample('cb-dependency-injection/ts/app/main.ts','bootstrap','app/main.ts')(format='.')
++makeExample('cb-dependency-injection/ts/app/app.module.ts','bootstrap','app/app.module.ts')(format='.')
a(id="injectable")
a(id="nested-dependencies")
@@ -872,33 +872,12 @@ a(id="forwardref")
The *Parent Finder* sample is full of circular class references that are impossible to break.
- In the [*Alex/Cathy* example](#known-parent) above:
-
- * the `AlexComponent` lists the `CathyComponent` in its component metadata `directives` array
- so it can display *Cathy* in its template.
-
- * the `CathyComponent` constructor injects the parent `AlexComponent` which means that the `alex` parameter
- of its constructor has the `AlexComponent` type.
-
- *Alex* refers to *Cathy* and *Cathy* refers to *Alex*. We're stuck. We must define one of them first.
-
- We defined *Alex* first and built its `C_DIRECTIVES` array with a forward reference to *Cathy*:
-+makeExample('cb-dependency-injection/ts/app/parent-finder.component.ts','C_DIRECTIVES','parent-finder.component.ts (C_DIRECTIVES)')(format='.')
:marked
-.l-sub-section
- :marked
- Defining *Alex* and *Cathy* in separate files won't help.
- *Alex* would have to import *Cathy* and *Cathy* would have to import *Alex*.
-
- We *had* to define *Alex* first because,
- while we can add `forwardRef(CathyComponent)` to *Alex*'s `directives` array,
- we can't write `public alex: forwardRef(AlexComponent))` in *Cathy*'s constructor.
-:marked
- We face a similar dilemma when a class makes *a reference to itself*
+ We face this dilemma when a class makes *a reference to itself*
as does the `AlexComponent` in its `providers` array.
The `providers` array is a property of the `@Component` decorator function which must
appear *above* the class definition.
- Again we break the circularity with `forwardRef`:
+ We break the circularity with `forwardRef`:
+makeExample('cb-dependency-injection/ts/app/parent-finder.component.ts','alex-providers','parent-finder.component.ts (AlexComponent providers)')(format='.')
:marked
diff --git a/public/docs/ts/latest/cookbook/dynamic-form-deprecated.jade b/public/docs/ts/latest/cookbook/dynamic-form-deprecated.jade
index 453b46bc7d..029c7c7743 100644
--- a/public/docs/ts/latest/cookbook/dynamic-form-deprecated.jade
+++ b/public/docs/ts/latest/cookbook/dynamic-form-deprecated.jade
@@ -2,7 +2,7 @@ include ../_util-fns
.alert.is-important
:marked
- This cookbook is using the deprecated forms API.
+ This cookbook is using the deprecated forms API, which is disabled as of RC5, thus this sample only works up to RC4.
We have created a new version of this cookbook using the new API here.
diff --git a/public/docs/ts/latest/cookbook/dynamic-form.jade b/public/docs/ts/latest/cookbook/dynamic-form.jade
index 2c865b64cf..705fadc488 100644
--- a/public/docs/ts/latest/cookbook/dynamic-form.jade
+++ b/public/docs/ts/latest/cookbook/dynamic-form.jade
@@ -1,11 +1,5 @@
include ../_util-fns
-.alert.is-important
- :marked
- This cookbook uses the new forms API.
-
- The old forms API is deprecated, but we still maintain a separate version of the cookbook using the deprecated forms API here.
-
:marked
We can't always justify the cost and time to build handcrafted forms,
especially if we'll need a great number of them, they're similar to each other, and they change frequently
@@ -44,16 +38,21 @@ include ../_util-fns
:marked
## Bootstrap
- During bootstrap we have to register the new forms module by calling `provideForms()` and pass the result to the provider array.
+ We start by creating an `NgModule` called `AppModule`.
-+makeExample('cb-dynamic-form/ts/app/main.ts','','app/main.ts')
-
-:marked
- The old forms API is going through a deprecation phase. During this transition Angular is supporting both form modules.
-
- To remind us that the old API is deprecated, Angular will print a warning message to the console.
+ In our example we will be using Reactive Forms.
- Since we are converting to the new API, and no longer need the old API, we call `disableDeprecatedForms()` to disable the old form functionality and the warning message.
+ Reactive Forms belongs to a different `NgModule` called `ReactiveFormsModule`, so in order to access any Reactive Forms directives, we have to import `ReactiveFormsModule` from `AppModule`.
+
+ We bootstrap our `AppModule` in main.ts.
+
++makeTabs(
+ `cb-dynamic-form/ts/app/app.module.ts,
+ cb-dynamic-form/ts/app/main.ts`,
+ null,
+ `app.module.ts,
+ main.ts`
+)
.l-main-section
@@ -121,9 +120,7 @@ include ../_util-fns
In both components we're relying on Angular's **formGroup** to connect the template HTML to the
underlying control objects, populated from the question model with display and validation rules.
- `formControlName` and `formGroup` have to be registered as directives before we can use them in our templates.
-
- It turns out we get access to all form directives by importing and registering `REACTIVE_FORM_DIRECTIVES`.
+ `formControlName` and `formGroup` are directives defined in `ReactiveFormsModule`. Our templates can can access these directives directly since we imported `ReactiveFormsModule` from `AppModule`.
:marked
diff --git a/public/docs/ts/latest/cookbook/set-document-title.jade b/public/docs/ts/latest/cookbook/set-document-title.jade
index f25fe798f8..60fa73a49b 100644
--- a/public/docs/ts/latest/cookbook/set-document-title.jade
+++ b/public/docs/ts/latest/cookbook/set-document-title.jade
@@ -38,18 +38,8 @@ code-example(format='').
for getting and setting the current HTML document title:
* `getTitle() : string` — Gets the title of the current HTML document.
- * `setTitle( newTitle : string )` — Sets the title of the current HTML document.
-
- While this class is part of the Browser platform package, it is *not part of the default Browser
- platform providers* that Angular loads automatically.
- This means as we bootstrap our application using the Browser platform `boostrap()`
- function, we'll also have to include `Title` service explicitly as one of the bootstrap providers:
-
-+makeExample( "cb-set-document-title/ts/app/main.ts", "bootstrap-title", "app/main.ts (provide Title service)" )(format='.')
-:marked
- Once we've explicitly provided the `Title` service we can then inject the `Title` service into any of our
- custom application components and services.
-
+ * `setTitle( newTitle : string )` — Sets the title of the current HTML document.
+
Let's inject the `Title` service into the root `AppComponent` and expose a bindable `setTitle` method that calls it:
+makeExample( "cb-set-document-title/ts/app/app.component.ts", "class", "app/app.component.ts (class)" )(format='.')
@@ -63,9 +53,10 @@ figure.image-display
+makeTabs(
`cb-set-document-title/ts/app/main.ts,
- cb-set-document-title/ts/app/app.component.ts`,
- '',
- 'app/main.ts, app/app.component.ts' )
+ cb-set-document-title/ts/app/app.module.ts,
+ cb-set-document-title/ts/app/app.component.ts`,
+ '',
+ 'app/main.ts, app/app.module.ts, app/app.component.ts' )
//
Todo: tie this back to the router so we can see how to use this Title service to (re)set the title
diff --git a/public/docs/ts/latest/glossary.jade b/public/docs/ts/latest/glossary.jade
index 50c6100cda..3342e16d0f 100644
--- a/public/docs/ts/latest/glossary.jade
+++ b/public/docs/ts/latest/glossary.jade
@@ -21,6 +21,19 @@ include _util-fns
// #enddocregion a1
.l-main-section
+
+:marked
+ ## Angular Module
+.l-sub-section
+ :marked
+ Helps us organize an application into cohesive blocks of functionality.
+ An Angular module identifies the components, directives, and pipes that are used by the application
+ along with the list of external Angular modules that the application needs, such as `FormsModule`.
+
+ Every Angular application has an application root module class. By convention the class is
+ called `AppModule` and resides in a file named `app.component.ts`.
+
+ See the [Angular Module](/docs/ts/latest/guide/ngmodule.html) chapter for details and examples.
:marked
## Annotation
.l-sub-section
@@ -50,10 +63,10 @@ include _util-fns
## Barrel
.l-sub-section
:marked
- A barrel is a way to *rollup exports* from several modules into a single convenience module.
- The barrel itself is a module file that re-exports *selected* exports of other modules.
+ A barrel is a way to *rollup exports* from several ES2015 modules into a single convenience ES2015 module.
+ The barrel itself is an ES2015 module file that re-exports *selected* exports of other ES2015 modules.
- Imagine three modules in a `heroes` folder:
+ Imagine three ES2015 modules in a `heroes` folder:
code-example.
// heroes/hero.component.ts
export class HeroComponent {}
@@ -81,12 +94,17 @@ include _util-fns
import { Hero, HeroService } from '../heroes'; // index is implied
:marked
The Angular [scoped packages](#scoped-package) each have a barrel named `index`.
+
// #enddocregion b-c
:marked
That's why we can write this:
+makeExcerpt('quickstart/ts/app/app.component.ts', 'import', '')
// #docregion b-c
+.alert.is-important
+ :marked
+ Note that you can often achieve this same goal using [Angular modules](#angular-module) instead.
+
:marked
## Binding
.l-sub-section
@@ -102,10 +120,9 @@ include _util-fns
## Bootstrap
.l-sub-section
:marked
- We launch an Angular application by "bootstrapping" it with the `bootstrap` method.
- The `bootstrap` method identifies an application's top level "root" [Component](#component)
- and optionally registers service [providers](#provider) with the
- [dependency injection system](#dependency-injection).
+ We launch an Angular application by "bootstrapping" it using the application root Angular module (`AppModule`).
+ The bootstraping identifies an application's top level "root" [Component](#component), which is the first
+ component that is loaded for the application. For more information see the [QuickStart](/docs/ts/latest/quickstart.html).
One can bootstrap multiple apps in the same `index.html`, each with its own top level root.
@@ -271,9 +288,7 @@ include _util-fns
Registering providers is a critical preparatory step.
Angular registers some of its own providers with every injector.
- We can register our own providers. Quite often the best time to register a `Provider`
- is when we [bootstrap](#bootstrap) the application.
- There are other opportunities to register as well.
+ We can register our own providers.
Learn more in the [Dependency Injection](/docs/ts/latest/guide/dependency-injection.html) chapter.
:marked
@@ -450,6 +465,14 @@ include _util-fns
:marked
## Module
.l-sub-section
+
+ .alert.is-important
+ :marked
+ In Angular, there are two types of modules:
+ - [Angular modules](#angular-module).
+ See the [Angular Module](/docs/ts/latest/guide/ngmodule.html) chapter for details and examples.
+ - ES2015 modules as described in this section.
+
:marked
Angular apps are modular.
@@ -487,6 +510,17 @@ include _util-fns
.l-main-section
+:marked
+ ## Observable
+.l-sub-section
+ :marked
+ We can think of an observable as an array whose items arrive asynchronously over time.
+ Observables help us manage asynchronous data, such as data coming from a backend service.
+ Observables are used within Angular itself, including Angular's event system and its http client service.
+
+ To use observables, Angular uses a third-party library called Reactive Extensions (RxJS).
+ Observables are a proposed feature for ES 2016, the next version of JavaScript.
+
:marked
## Output
.l-sub-section
@@ -505,7 +539,7 @@ include _util-fns
.l-sub-section
:marked
The practice of writing compound words or phrases such that each word or abbreviation begins with a capital letter.
- Class names are typically spelled in PascalCase. Examples include: `Person` and `Customer`.
+ Class names are typically spelled in PascalCase. Examples include: `Person` and `HeroDetailComponent`.
This form is also known as **upper camel case**, to distinguish it from **lower camel case** which we simply call [camelCase](#camelcase).
In this documentation, "PascalCase" means *upper camel case* and "camelCase" means *lower camel case*.
@@ -516,7 +550,7 @@ include _util-fns
:marked
An Angular pipe is a function that transforms input values to output values for
display in a [view](#view). We use the `#{atSym}Pipe` !{decorator}
- to associate the pipe function with a name. We then can use that
+ to associate the pipe function with a name. We can then use that
name in our HTML to declaratively transform values on screen.
Here's an example that uses the built-in `currency` pipe to display
@@ -543,6 +577,23 @@ include _util-fns
.l-main-section
+
+:marked
+ ## Reactive Forms
+.l-sub-section
+ :marked
+ A technique for building Angular forms through code in a component.
+ The alternate technique is [Template-Driven Forms](#template-driven-forms).
+
+ When building reactive forms:
+ - The "source of truth" is the component. The validation is defined using code in the component.
+ - Each control is explicitly created in the component class with `new FormControl()` or with `FormBuilder`.
+ - The template input elements do *not* use `ngModel`.
+ - The associated Angular directives are all prefixed with `Form` such as `FormGroup`, `FormControl`, and `FormControlName`.
+
+ Reactive forms are powerful, flexible, and great for more complex data entry form scenarios, such as dynamic generation
+ of form controls.
+
:marked
## Router
.l-sub-section
@@ -555,18 +606,32 @@ include _util-fns
The Angular [Component Router](/docs/ts/latest/guide/router.html) is a richly featured mechanism for configuring
and managing the entire view navigation process including the creation and destruction
of views.
+
+ In most cases, components becomes attached to a [router](#router) by means
+ of a `RouterConfig` that defines routes to views.
+
+ A [routing component's](#routing-component) template has a `RouterOutlet` element where it can display views produced by the router.
+
+ Other views in the application likely have anchor tags or buttons with `RouterLink` directives that users can click to navigate.
+
+ See the [Component Router](/docs/ts/latest/guide/router.html) chapter to learn more.
+
+:marked
+ ## RouterModule
+.l-sub-section
+ :marked
+ A separate [Angular module](#angular-module) that provides the necessary service providers and directives for navigating through application views.
+
+ See the [Component Router](/docs/ts/latest/guide/router.html) chapter to learn more.
+
+
:marked
## Routing Component
.l-sub-section
:marked
- A [Component](#component) with an attached router.
+ An Angular [Component](#component) with a RouterOutlet that displays views based on router navigations.
- In most cases, the component became attached to a [router](#router) by means
- of a `#{atSym}RouterConfig` #{decorator} that defined routes to views controlled by this component.
-
- The component's template has a `RouterOutlet` element where it can display views produced by the router.
-
- It likely has anchor tags or buttons with `RouterLink` directives that users can click to navigate.
+ See the [Component Router](/docs/ts/latest/guide/router.html) chapter to learn more.
.l-main-section
@@ -587,6 +652,23 @@ include _util-fns
+makeExcerpt('architecture/ts/app/app.component.ts', 'import', '')
// #docregion n-s-2
+:marked
+ ## Service
+.l-sub-section
+ :marked
+ Components are great and all … but what do we do with data or logic that are not associated
+ with a specific view or that we want to share across components? We build services!
+
+ Applications often require services such as a hero data service or a logging service.
+ Our components depend on these services to do the heavy lifting.
+
+ A service is a class with a focused purpose.
+ We often create a service to implement features that are
+ independent from any specific view,
+ provide share data or logic across components, or encapsulate external interactions.
+
+ See the [Services](/docs/ts/latest/tutorial/toh-pt4.html) chapter of the tutorial to learn more.
+
:marked
## Structural Directive
.l-sub-section
@@ -597,6 +679,8 @@ include _util-fns
The `ngIf` "conditional element" directive and the `ngFor` "repeater" directive are
good examples in this category.
+
+ See the [Structural Directives](/docs/ts/latest/guide/structural-directives.html) chapter to learn more.
// #enddocregion n-s-2
// #docregion t1
@@ -612,11 +696,31 @@ include _util-fns
We write templates in a special [Template Syntax](/docs/ts/latest/guide/template-syntax.html).
+
+:marked
+ ## Template-Driven Forms
+.l-sub-section
+ :marked
+ A technique for building Angular forms using HTML forms and input elements in the view.
+ The alternate technique is [Reactive Forms](#reactive-forms).
+
+ When building template-driven forms:
+ - The "source of truth" is the template. The validation is defined using attributes on the individual input elements.
+ - [Two-way binding](#data-binding) with `ngModel` keeps the component model in synchronization with the user's entry into the input elements.
+ - Behind the scenes, Angular creates a new control for each input element that has a `name` attribute and
+ two-way binding set up.
+ - The associated Angular directives are all prefixed with `ng` such as `ngForm`, `ngModel`, and `ngModelGroup`.
+
+ Template-driven forms are convenient, quick, and simple and are a good choice for many basic data entry form scenarios.
+
+ Learn how to build template-driven forms
+ in the [Forms](/docs/ts/latest/guide/forms.html) chapter.
+
:marked
## Template Expression
.l-sub-section
:marked
- An expression in a JavaScript-like syntax that Angular evaluates within
+ An expression is a JavaScript-like syntax that Angular evaluates within
a [data binding](#data-binding). Learn how to write template expressions
in the [Template Syntax](/docs/ts/latest/guide/template-syntax.html#template-expressions) chapter.
diff --git a/public/docs/ts/latest/guide/_data.json b/public/docs/ts/latest/guide/_data.json
index 3bc69e1c15..b59ef46195 100644
--- a/public/docs/ts/latest/guide/_data.json
+++ b/public/docs/ts/latest/guide/_data.json
@@ -33,15 +33,15 @@
"title": "Forms",
"intro": "A form creates a cohesive, effective, and compelling data entry experience. An Angular form coordinates a set of data-bound user controls, tracks changes, validates input, and presents errors.",
"nextable": true,
- "basics": true,
- "hide": true
+ "basics": true
},
"forms-deprecated": {
"title": "Forms",
"intro": "A form creates a cohesive, effective, and compelling data entry experience. An Angular form coordinates a set of data-bound user controls, tracks changes, validates input, and presents errors.",
"nextable": true,
- "basics": true
+ "basics": true,
+ "hide": true
},
"dependency-injection": {
diff --git a/public/docs/ts/latest/guide/architecture.jade b/public/docs/ts/latest/guide/architecture.jade
index 3510c864bb..a13f303e0d 100644
--- a/public/docs/ts/latest/guide/architecture.jade
+++ b/public/docs/ts/latest/guide/architecture.jade
@@ -12,10 +12,11 @@ block angular-parts
The framework consists of several cooperating libraries, some of them core and some optional.
:marked
- With Angular, we write applications by composing HTML *templates* with Angularized-markup,
+ We write Angular applications by composing HTML *templates* with Angularized-markup,
writing *component* classes to manage those templates, adding application logic in *services*,
- and handing the top root component to Angular's *bootstrapper*.
-
+ and boxing components and services in *modules*.
+
+ Then we launch the app by *bootstrapping* the top _root module_.
Angular takes over, presenting our application content in a browser and
responding to user interactions according to the instructions we provided.
@@ -49,118 +50,114 @@ figure
figure
img(src="/resources/images/devguide/architecture/module.png" alt="Component" align="left" style="width:240px; margin-left:-40px;margin-right:10px" )
:marked
- Angular apps are modular.
+ Angular apps are modular and Angular has its own modularity system called _Angular Modules_
+ or, occasionally, _NgModules_.
- In general we assemble our application from many **modules**.
+ _Angular Modules_ are a big deal.
+ We can only introduce them there; the [Angular Modules](ngmodule.html) chapter covers them in depth.
- A typical module is a cohesive block of code dedicated to a single purpose.
- A module **exports** something of value in that code, typically one thing such as a class.
-
-
-block modules-in-dart
- //- N/A
-
-block modules-are-optional
- .l-sub-section
- :marked
- ### Modules are optional
- We highly recommend modular design. TypeScript has great support for ES2015 module syntax and our chapters assume we're taking a modular
- approach using that syntax. That's why we list *Module* among the basic building blocks.
-
- Angular itself doesn't require a modular approach nor this particular syntax. Don't use it if you don't want it.
- Each chapter has plenty to offer after you steer clear of the `import` and `export` statements.
-
- Find setup and organization clues in the JavaScript track (select it from the combo-box at the top of this page)
- which demonstrates Angular 2 development with plain old JavaScript and no module system.
-
-- var _app_comp_filename = _docsFor == 'dart' ? 'app_component.dart' : 'app.component.ts';
+
:marked
- Perhaps the first module we meet is a module that exports a *component* class.
- The component is one of the basic Angular blocks, we write a lot of them,
- and we'll talk about components in the next segment. For the moment it is enough to know that a
- component class is the kind of thing we'd export from a module.
+ Every Angular app has at least one module, the _root module_, conventionally named `AppModule`.
- Most applications have an `AppComponent`. By convention, we'll find it in a file named `!{_app_comp_filename}`.
- Look inside such a file and we'll see a declaration such as this one.
+ While the _root_ module may be the only module in a small application, most apps have many more
+ _feature_ modules, each a cohesive block of code dedicated to an application domain,
+ a workflow, or a closely-related set of capabilities.
-+makeExcerpt('app/app.component.ts ()', 'export')
-
-block export-qualifier
+ An Angular module, whether a _root_ or _feature_, is a class with an `@NgModule` decorator.
+.l-sub-section
:marked
- The `export` statement tells TypeScript that this is a module whose
- `AppComponent` class is public and accessible to other modules of the application.
-
+ Decorators are functions that modify JavaScript classes.
+ Angular has many decorators that attach metadata to classes so that it knows
+ what those classes mean and how they should work.
+
+ Learn more about decorators on the web.
:marked
- When we need a reference to the `AppComponent`, we **import** it like this:
+ `NgModule` is a decorator function that takes a single metadata object whose properties describe the module.
+ The most important are
+ * `declarations` - the _view classes_ that belong to this module.
+ Angular has three kinds of view classes: [components](#components), [directives](#directives) and [pipes](pipes.html).
-+makeExcerpt('app/main.ts', 'import')
+ * `exports` - subset of declarations that should be visible and usable in the component [templates](#templates) of other modules.
-block ts-import
+ * `imports` - other modules whose exported classes are needed by component templates declared in _this_ module.
+
+ * `providers` creators of [services](#services) that this module contributes to
+ the global collection of services; they become accessible in all parts of the app.
+
+ * `bootstrap` - identifies the main application view, called the _root component_,
+ that hosts all other app views. Only the _root module_ should set this `bootstrap` property.
+
+ Here's a simple root module:
++makeExample('app/mini-app.ts', 'module', 'app/app.module.ts')(format='.')
+
+.l-sub-section
:marked
- The `import` statement tells the system it can get an `AppComponent` from a module named `app.component`
- located in a neighboring file.
- The **module name** (AKA module id) is often the same as the filename without its extension.
+ The `export` of `AppComponent` is just for show.
+ A root module has no reason to export anything because ... it's the root.
+ We don't expect other modules to import the root module.
+
+ But if one did, it could use the `AppComponent` in its component templates.
+:marked
+ We launch an application by _bootstrapping_ its root module.
+ During development we're likely to bootstrap the `AppModule` in a `main.ts` file like this one.
+
++makeExample('app/main.ts', '', 'app/main.ts')(format='.')
:marked
- ### Libraries
+ ### Angular Modules vs. JavaScript Modules
+
+ The Angular module — a class decorated with `@NgModule` — is a fundamental feature of Angular itself.
+
+ JavaScript also has its own module system for managing collections of JavaScript objects.
+ It's completely different and unrelated to the Angular module system.
+
+ In JavaScript each _file_ is a module and all objects defined in the file belong to that module.
+ The module declares some objects to be public by marking them with the `export` key word.
+ Other JavaScript modules use *import statements* to access public objects from other modules.
+
++makeExample('app/app.module.ts', 'imports', '')(format='.')
++makeExample('app/app.module.ts', 'export', '')(format='.')
+
+.l-sub-section
+ :marked
+ Learn more about the JavaScript module system on the web.
+:marked
+ These are two different and _complementary_ module systems. We use them both to write our apps.
+
+ ### Angular Libraries
figure
img(src="/resources/images/devguide/architecture/library-module.png" alt="Component" align="left" style="width:240px; margin-left:-40px;margin-right:10px" )
-block angular-library-modules
- :marked
- Some modules are _libraries_ of other modules.
- Angular itself ships as a collection of library modules within several npm packages.
- Their names begin with the `!{_at_angular}` prefix.
-
- Each Angular library contains a [barrel](../glossary.html#barrel) module
- that is actually a public façade over several logically-related private modules.
-
:marked
- `!{_at_angular}/core` is the primary Angular library from which we get most of what we need.
-
+ Angular itself ships as a collection of JavaScript modules. We can think of them as library modules.
- There are other important Angular libraries too, such as `!{_at_angular}/common`,
- `!{_at_angular}/http` and `!{_at_angular}/router`.
- We import what we need from an Angular !{_library_module}.
-
-block angular-imports
- :marked
- For example, we import the Angular **`Component` *function*** from `@angular/core` like this:
- +makeExcerpt('app/app.component.ts', 'import')
- :marked
- Compare that syntax to our previous import of `AppComponent`.
- +makeExcerpt('app/main.ts', 'import')
-
- :marked
- Notice the difference?
- In the first case, when importing from an Angular library module,
- the import statement refers to the bare module name, `@angular/core`, *without a path prefix*.
-
- When we import from one of *our* own files, we prefix the module name with the file path.
- In this example we specify a relative file path (`./`). That means the
- source module is in the same folder (`./`) as the module importing it.
- We could path up and around the application folder structure if the source module were somewhere else.
- .l-sub-section
- :marked
- We import and export in the ECMAScript 2015 (ES2015) module syntax.
- Learn more about that syntax [here](http://www.2ality.com/2014/09/es6-modules-final.html)
- and many other places on the web.
-
- The infrastructure *behind* module loading and importing is an important subject.
- But it's a subject outside the scope of this introduction to Angular.
- While we're focused on our application, *import* and *export*
- is about all we need to know.
-
-- var _export = _docsFor == 'dart' ? 'publicly declare' : 'export';
-- var _declare = _docsFor == 'dart' ? 'declare' : 'export';
+ Each Angular library name begin with the `!{_at_angular}` prefix.
+
+ We install them with the **npm** package manager and import parts of them with JavaScript `import` statements.
+
:marked
- The key take-aways are:
- * Angular apps are composed of modules.
- * Modules !{_export} things — classes, function, values — that other modules import.
- * We prefer to write our application as a collection of modules, each module exporting one thing.
+ For example, we import Angular's `Component` decorator from the `@angular/core` library like this:
++makeExample('app/app.component.ts', 'import', '')(format='.')
+:marked
+ We also import Angular _modules_ from Angular _libraries_ using JavaScript import statements:
++makeExample('app/mini-app.ts', 'import-browser-module', '')(format='.')
+:marked
+ Our application module needs material from within that `BrowserModule`
+ so we add it to the `@NgModule` metadata `imports` like this.
++makeExample('app/mini-app.ts', 'ngmodule-imports', '')(format='.')
+:marked
+ We're using both the Angular and JavaScript module systems _together_.
- The first module we write will most likely !{_declare} a component.
+ It's easy to confuse the two systems because they share the common vocabulary of "imports" and "exports".
+ Hang in there. The confusion will yield to clarity with time and experience.
+
+.l-sub-section
+ :marked
+ Learn more in the [Angular Modules](ngmodule.html) chapter.
+
+.l-hr
.l-main-section
:marked
@@ -192,6 +189,8 @@ figure
For the moment, have faith that Angular will call the constructor and deliver an
appropriate `HeroService` when we need it.
+.l-hr
+
.l-main-section
:marked
## Templates
@@ -231,6 +230,8 @@ figure
In this manner we'll compose complex component trees to build out our richly featured application.
+.l-hr
+
.l-main-section
:marked
## Metadata
@@ -259,7 +260,6 @@ figure
block ts-decorator
:marked
- A decorator is a function. Decorators often have a configuration parameter.
The `@Component` decorator takes a required configuration object with the
information Angular needs to create and present the component and its view.
@@ -299,6 +299,8 @@ figure
The architectural takeaway is that we must add metadata to our code
so that Angular knows what to do.
+.l-hr
+
.l-main-section
:marked
## Data binding
@@ -357,6 +359,8 @@ figure
Data binding is also important for communication between parent and child components.
+.l-hr
+
.l-main-section
:marked
## Directives
@@ -417,6 +421,8 @@ block dart-bool
`HeroListComponent` are one kind of custom directive.
+.l-hr
+
.l-main-section
:marked
## Services
@@ -469,6 +475,8 @@ figure
Angular does help us *follow* these principles by making it easy to factor our
application logic into services and make those services available to components through *dependency injection*.
+.l-hr
+
.l-main-section
:marked
## Dependency injection
@@ -503,18 +511,19 @@ figure
If the injector doesn't have a `HeroService`, how does it know how to make one?
In brief, we must have previously registered a **provider** of the `HeroService` with the injector.
- A provider is something that can create or return a service, typically the service class itself.
+ A provider is something that can create or return a service, typically the service class itself.
- We can register providers at any level of the application component tree.
- We often do so at the root when we bootstrap the application so that
- the same instance of a service is available everywhere.
+ We can register providers in modules or in components.
-+makeExcerpt('app/main.ts', 'bootstrap')
+ We often add providers to the [root module](#module) so that
+ the same instance of a service is available everywhere.
+
++makeExample('app/app.module.ts', 'providers', 'app/app.module.ts (module providers)')(format='.')
:marked
- Alternatively, we might register at a component level, in the providers property of the `@Component` metadata:
+ Alternatively, we might register at a component level in the `providers` property of the `@Component` metadata:
-+makeExcerpt('app/hero-list.component.ts', 'providers')
++makeExample('app/hero-list.component.ts', 'providers', 'app/hero-list.component.ts (component providers)')(format='.')
:marked
Registering at a component level means we get a new instance of the
@@ -535,6 +544,8 @@ figure
* We register *providers* with injectors.
+.l-hr
+
.l-main-section
:marked
## Wrap up
@@ -560,15 +571,10 @@ figure
> [**Animations**](animations.html): The animation library makes it easy for developers to animate component behavior
without deep knowledge of animation techniques or CSS.
- > **Bootstrap**: A method to configure and launch the root application component.
-
> **Change detection**: Learn how Angular decides that a component property value has changed and
when to update the screen.
Learn how it uses **zones** to intercept asynchronous activity and run its change detection strategies.
- > **Component router**: With the component Router service, users can navigate a multi-screen application
- in a familiar web browsing style using URLs.
-
> **Events**: The DOM raises events. So can components and services. Angular offers mechanisms for
publishing and subscribing to events.
diff --git a/public/docs/ts/latest/guide/attribute-directives.jade b/public/docs/ts/latest/guide/attribute-directives.jade
index e6f0db9472..b27047af9c 100644
--- a/public/docs/ts/latest/guide/attribute-directives.jade
+++ b/public/docs/ts/latest/guide/attribute-directives.jade
@@ -126,10 +126,11 @@ p
Meanwhile, we'll revise the `AppComponent` to reference this template.
+makeExample('attribute-directives/ts/app/app.component.ts',null,'app/app.component.ts')
:marked
- We've added an `import` statement to fetch the 'Highlight' directive and,
- added that class to a `directives` component metadata so that Angular
+ We'll add an `import` statement to fetch the 'Highlight' directive and,
+ added that class to the `declarations` NgModule metadata so that Angular
will recognize our directive when it encounters `myHighlight` in the template.
-
++makeExample('attribute-directives/ts/app/app.module.ts',null,'app/app.module.ts')
+:marked
We run the app and see that our directive highlights the paragraph text.
figure.image-display
@@ -138,15 +139,15 @@ figure.image-display
:marked
### Your directive isn't working?
- Did you remember to set the `directives` attribute of `@Component`? It is easy to forget!
+ Did you remember to add the directive to the the `declarations` attribute of `@NgModule`? It is easy to forget!
Open the console in the browser tools and look for an error like this:
code-example(format="nocode").
EXCEPTION: Template parse errors:
- Can't bind to 'myHighlight' since it isn't a known native property
+ Can't bind to 'myHighlight' since it isn't a known property of 'p'.
:marked
Angular detects that we're trying to bind to *something* but it doesn't know what.
- We have to tell it by listing `HighlightDirective` in the `directives` metadata array.
+ We have to tell it by listing `HighlightDirective` in the `declarations` metadata array.
:marked
Let's recap what happened.
@@ -318,6 +319,7 @@ figure.image-display
`attribute-directives/ts/app/app.component.ts,
attribute-directives/ts/app/app.component.html,
attribute-directives/ts/app/highlight.directive.ts,
+ attribute-directives/ts/app/app.module.ts,
attribute-directives/ts/app/main.ts,
attribute-directives/ts/index.html
`,
@@ -325,6 +327,7 @@ figure.image-display
`app.component.ts,
app.component.html,
highlight.directive.ts,
+ app.module.ts,
main.ts,
index.html
`)
diff --git a/public/docs/ts/latest/guide/dependency-injection.jade b/public/docs/ts/latest/guide/dependency-injection.jade
index 2ad5b7a7ed..8755cbec03 100644
--- a/public/docs/ts/latest/guide/dependency-injection.jade
+++ b/public/docs/ts/latest/guide/dependency-injection.jade
@@ -253,37 +253,37 @@ block ctor-syntax
We do have to configure the injector by registering the **providers**
that create the services our application requires.
We'll explain what [providers](#providers) are later in this chapter.
- Before we do, let's see an example of provider registration during bootstrapping:
-+makeExample('dependency-injection/ts/app/main.1.ts', 'bootstrap-discouraged')(format='.')
+ We can either register a provider within an [NgModule](ngmodule.html) or in application components
-:marked
- The injector now knows about our `HeroService`.
- An instance of our `HeroService` will be available for injection across our entire application.
+ ### Registering providers in an NgModule
+ Here's our AppModule where we register a `Logger`, an `UserService`, and an `APP_CONFIG` provider.
- Of course we can't help wondering about that comment telling us not to do it this way.
- It *will* work. It's just not a best practice.
- The bootstrap provider option is intended for configuring and overriding Angular's own
- preregistered services, such as its routing support.
-
- The preferred approach is to register application providers in application components.
+- var stylePattern = { otl: /(providers)/ };
++makeExample('dependency-injection/ts/app/app.module.ts', 'ngmodule','app/app.module.ts', stylePattern)(format='.')
+
:marked
### Registering providers in a component
Here's a revised `HeroesComponent` that registers the `HeroService`.
-- var stylePattern = { otl: /(providers:.*),/ };
+makeExample('dependency-injection/ts/app/heroes/heroes.component.1.ts', 'full','app/heroes/heroes.component.ts', stylePattern)(format='.')
:marked
- Look closely at the `providers` part of the `@Component` metadata.
- An instance of the `HeroService` is now available for injection in this `HeroesComponent`
- and all of its child components.
+ ### When to use the NgModule and when an application component?
+ On the one hand, a provider in an NgModule is registered in the root injector. That means that every provider
+ registered within an NgModule will be accessible in the entire application.
- The `HeroesComponent` itself doesn't happen to need the `HeroService`.
- But its child `HeroListComponent` does, so we head there next.
+ On the other hand, a provider registered in an application component is available only on that component and all its children.
+
+ We want the `APP_CONFIG` service to be available all across the application, but a `HeroService` is only used within the *Heroes*
+ feature area — and nowhere else. —
+
+.l-sub-section
+ :marked
+ Read also **Should I add providers to the root AppModule or the root AppComponent?** at the [NgModule](ngmodule.html#q-root-component-or-module) chapter.
:marked
### Preparing the HeroListComponent for injection
@@ -470,9 +470,9 @@ block real-logger
:marked
We're likely to need the same logger service everywhere in our application,
so we put it in the project's `#{_appDir}` folder, and
- we register it in the `providers` #{_array} of the metadata for our application root component, `AppComponent`.
+ we register it in the `providers` #{_array} of the metadata for our application module, `AppModule`.
-+makeExcerpt('app/providers.component.ts','providers-logger','app/app.component.ts (excerpt)')
++makeExcerpt('app/providers.component.ts','providers-logger','app/app.module.ts (excerpt)')
:marked
If we forget to register the logger, Angular throws an exception when it first looks for the logger:
@@ -497,7 +497,7 @@ code-example(format="nocode").
We must register a service *provider* with the injector, or it won't know how to create the service.
- Earlier we registered the `Logger` service in the `providers` #{_array} of the metadata for the `AppComponent` like this:
+ Earlier we registered the `Logger` service in the `providers` #{_array} of the metadata for the `AppModule` like this:
+makeExample('dependency-injection/ts/app/providers.component.ts','providers-logger')
@@ -801,9 +801,9 @@ block what-should-we-use-as-token
block dart-map-alternative
:marked
- Or we can provide and inject the configuration object in our top-level `AppComponent`.
+ Or we can provide and inject the configuration object in an ngModule like `AppModule`.
- +makeExcerpt('app/app.component.ts','providers')
+ +makeExcerpt('app/app.module.ts','ngmodule-providers')
#optional
:marked
diff --git a/public/docs/ts/latest/guide/displaying-data.jade b/public/docs/ts/latest/guide/displaying-data.jade
index 5fbf0e7ff7..376c2d254c 100644
--- a/public/docs/ts/latest/guide/displaying-data.jade
+++ b/public/docs/ts/latest/guide/displaying-data.jade
@@ -278,6 +278,7 @@ block hero-class
block final-code
+makeTabs(`displaying-data/ts/app/app.component.ts,
displaying-data/ts/app/hero.ts,
+ displaying-data/ts/app/app.module.ts,
displaying-data/ts/app/main.ts`,
- 'final,,',
- 'app/app.component.ts, app/hero.ts, main.ts')
+ 'final,,,',
+ 'app/app.component.ts, app/hero.ts, app.module.ts, main.ts')
diff --git a/public/docs/ts/latest/guide/forms-deprecated.jade b/public/docs/ts/latest/guide/forms-deprecated.jade
index f29cb3087a..ad2d70a669 100644
--- a/public/docs/ts/latest/guide/forms-deprecated.jade
+++ b/public/docs/ts/latest/guide/forms-deprecated.jade
@@ -2,7 +2,7 @@ include ../_util-fns
.alert.is-important
:marked
- This guide is using the deprecated forms API.
+ This guide is using the deprecated forms API, which is disabled as of RC5, thus this sample only works up to RC4.
We have created a new version using the new API here.
diff --git a/public/docs/ts/latest/guide/forms.jade b/public/docs/ts/latest/guide/forms.jade
index 90facf5e1f..dbe9b8ded6 100644
--- a/public/docs/ts/latest/guide/forms.jade
+++ b/public/docs/ts/latest/guide/forms.jade
@@ -1,15 +1,7 @@
include ../_util-fns
-.alert.is-important
- :marked
- This guide is using the new forms API. To use this API, you must opt in by adding special
- providers to your bootstrap file (see the Bootstrap seection below).
-
- The old forms API is deprecated, but we still maintain a separate version of the guide using
- the deprecated forms API here.
-
:marked
- We’ve all used a form to login, submit a help request, place an order, book a flight,
+ We’ve all used a form to log in, submit a help request, place an order, book a flight,
schedule a meeting and perform countless other data entry tasks.
Forms are the mainstay of business applications.
@@ -23,38 +15,22 @@ include ../_util-fns
**two-way data binding, change tracking, validation, and error handling**
... which we shall cover in this chapter on Angular forms.
- We will build a simple form from scratch, one step at a time. Along the way we'll learn
+ We will build a simple form from scratch, one step at a time. Along the way we'll learn how to
- - to build an Angular form with a component and template
+ - build an Angular form with a component and template
- - two-way data binding with `[(ngModel)]` syntax for reading and writing values to input controls
+ - two-way data bind with `[(ngModel)]` syntax for reading and writing values to input controls
- - using `ngModel` in combination with a form lets us track the change state and validity of form controls
+ - track the change state and validity of form controls using `ngModel` in combination with a form
- - special CSS classes that follow the state of the controls and can be used to provide strong visual feedback
+ - provide strong visual feedback using special CSS classes that track the state of the controls
- - displaying validation errors to users and enable/disable form controls
+ - display validation errors to users and enable/disable form controls
- - sharing information among controls with template reference variables
+ - use [template reference variables](./template-syntax.html#ref-vars) for sharing information among HTML elements
Live Example
-.l-main-section
-:marked
- ## Bootstrap
-
- We start by showing how to bootstrap the application and add the necessary dependencies to use forms.
-
- During bootstrap we have to register the new forms module by calling `provideForms()` and pass the result to the provider array.
-+makeExample('forms/ts/app/main.ts','','app/main.ts')
-
-:marked
- The old forms API is going through a deprecation phase. During this transition Angular is supporting both form modules.
-
- To remind us that the old API is deprecated, Angular will print a warning message to the console.
-
- Since we are converting to the new API, and no longer need the old API, we call `disableDeprecatedForms()` to disable the old form functionality and the warning message.
-
.l-main-section
:marked
## Template-Driven Forms
@@ -101,7 +77,7 @@ figure.image-display
1. Create the component that controls the form
1. Create a template with the initial form layout
1. Bind data properties to each form input control with the `ngModel` two-way data binding syntax
- 1. Add the **#name** attribute to each form input control
+ 1. Add the `name` attribute to each form input control
1. Add custom CSS to provide visual feedback
1. Show and hide validation error messages
1. Handle form submission with **ngSubmit**
@@ -137,7 +113,8 @@ include ../_quickstart_repo
We can create a new hero like this:
code-example(format="").
let myHero = new Hero(42, 'SkyDog',
- 'Fetch any object at any distance', 'Leslie Rollover');
+ 'Fetch any object at any distance',
+ 'Leslie Rollover');
console.log('My hero is called ' + myHero.name); // "My hero is called SkyDog"
:marked
@@ -156,13 +133,15 @@ code-example(format="").
:marked
There’s nothing special about this component, nothing form-specific, nothing to distinguish it from any component we've written before.
- Understanding this component requires only the Angular 2 concepts we’ve learned in previous chapters
+ Understanding this component requires only the Angular concepts we’ve learned in previous chapters
1. We import the `Component` decorator from the Angular library as we usually do.
+ 1. We import the `Hero` model we just created.
+
1. The `@Component` selector value of "hero-form" means we can drop this form in a parent template with a `` tag.
- 1. The `templateUrl` property points to a separate file for template HTML called `hero-form.component.html`.
+ 1. The `templateUrl` property points to a separate file for the template HTML called `hero-form.component.html`.
1. We defined dummy data for `model` and `powers` as befits a demo.
Down the road, we can inject a data service to get and save real data
@@ -182,7 +161,38 @@ code-example(format="").
We made a good choice to put the HTML template elsewhere.
We'll write that template in a moment. Before we do, we'll take a step back
- and revise the `app.component.ts` to make use of our new `HeroFormComponent`.
+ and revise the `app.module.ts` and `app.component.ts` to make use of our new `HeroFormComponent`.
+
+.l-main-section
+:marked
+ ## Revise the *app.module.ts*
+
+ `app.module.ts` defines the application's root module. In it we identify the external modules we'll use in our application
+ and declare the components that belong to this module, such as our `HeroFormComponent`.
+
+ Because template-driven forms are in their own module, we need to add the `FormsModule` to the array of
+ `imports` for our application module before we can use forms.
+
+ Replace the contents of the "QuickStart" version with the following:
++makeExample('forms/ts/app/app.module.ts', null, 'app/app.module.ts')
+
+:marked
+.l-sub-section
+ :marked
+ There are three changes:
+
+ 1. We import `FormsModule` and our new `HeroFormComponent`.
+
+ 1. We add the `FormsModule` to the list of `imports` defined in the `ngModule` decorator. This gives our application
+ access to all of the template-driven forms features, including `ngModel`.
+
+ 1. We add the `HeroFormComponent` to the list of `declarations` defined in the `ngModule` decorator. This makes
+ the `HeroFormComponent` component visible throughout this module.
+
+.alert.is-important
+ :marked
+ If a component, directive, or pipe belongs to a module in the `imports` array, _DON'T_ declare it in the `declarations` array.
+ If you wrote it and it should belong to this module, _DO_ declare it in the `declarations` array.
.l-main-section
:marked
@@ -196,14 +206,10 @@ code-example(format="").
:marked
.l-sub-section
:marked
- There are only three changes:
-
- 1. We import the new `HeroFormComponent`.
+ There is only one changes:
1. The `template` is simply the new element tag identified by the component's `selector` property.
-
- 1. The `directives` array tells Angular that our template depends upon the `HeroFormComponent`
- which is itself a Directive (as are all Components).
+ This will display the hero form when the application component is loaded.
.l-main-section
:marked
@@ -220,11 +226,11 @@ code-example(format="").
The *Name* `` control has the HTML5 `required` attribute;
the *Alter Ego* `` control does not because `alterEgo` is optional.
- We've got a *Submit* button at the bottom with some classes on it.
+ We've got a *Submit* button at the bottom with some classes on it for styling.
**We are not using Angular yet**. There are no bindings. No extra directives. Just layout.
- The `container`,`form-group`, `form-control`, and `btn` classes
+ The `container`, `form-group`, `form-control`, and `btn` classes
come from [Twitter Bootstrap](http://getbootstrap.com/css/). Purely cosmetic.
We're using Bootstrap to gussy up our form.
Hey, what's a form without a little style!
@@ -295,7 +301,6 @@ figure.image-display
so we can see what we're doing.
We left ourselves a note to throw it away when we're done.
-
:marked
Focus on the binding syntax: `[(ngModel)]="..."`.
@@ -309,18 +314,33 @@ figure.image-display
The diagnostic is evidence that we really are flowing values from the input box to the model and
back again. **That's two-way data binding!**
- Notice that we also added a `name` attribute to our `` tag. This is a requirement when using `[(ngModel)]` in combination with a form, so that we can easily refer to it in the aggregate form value and validity state.
+ Notice that we also added a `name` attribute to our `` tag and set it to "name"
+ which makes sense for the hero's name. Any unique value will do, but using a descriptive name is helpful.
+ Defining a `name` attribute is a requirement when using `[(ngModel)]` in combination with a form.
- Let's add similar `[(ngModel)]` bindings to *Alter Ego* and *Hero Power*.
+.l-sub-section
+ :marked
+ Internally Angular creates `FormControls` and registers them with an `NgForm` directive that Angular
+ attached to the `