`,
styleUrls: ['app/app.component.css'],
directives: [ROUTER_DIRECTIVES],
providers: [
- ROUTER_PROVIDERS,
HeroService,
]
})
-@RouteConfig([
- { path: '/dashboard', name: 'Dashboard', component: DashboardComponent, useAsDefault: true },
- { path: '/detail/:id', name: 'HeroDetail', component: HeroDetailComponent },
- { path: '/heroes', name: 'Heroes', component: HeroesComponent }
-])
export class AppComponent {
title = 'Tour of Heroes';
}
diff --git a/public/docs/_examples/toh-6/ts/app/app.routes.ts b/public/docs/_examples/toh-6/ts/app/app.routes.ts
new file mode 100644
index 0000000000..b299102385
--- /dev/null
+++ b/public/docs/_examples/toh-6/ts/app/app.routes.ts
@@ -0,0 +1,30 @@
+// #docregion
+import { provideRouter, RouterConfig } from '@angular/router';
+
+import { DashboardComponent } from './dashboard.component';
+import { HeroesComponent } from './heroes.component';
+import { HeroDetailComponent } from './hero-detail.component';
+
+export const routes: RouterConfig = [
+ {
+ path: '',
+ redirectTo: '/dashboard',
+ terminal: true
+ },
+ {
+ path: 'dashboard',
+ component: DashboardComponent
+ },
+ {
+ path: 'detail/:id',
+ component: HeroDetailComponent
+ },
+ {
+ path: 'heroes',
+ component: HeroesComponent
+ }
+];
+
+export const APP_ROUTER_PROVIDERS = [
+ provideRouter(routes)
+];
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 8ca1e3a2e2..08ffecc0ea 100644
--- a/public/docs/_examples/toh-6/ts/app/dashboard.component.ts
+++ b/public/docs/_examples/toh-6/ts/app/dashboard.component.ts
@@ -1,7 +1,7 @@
// #docplaster
// #docregion
import { Component, OnInit } from '@angular/core';
-import { Router } from '@angular/router-deprecated';
+import { Router } from '@angular/router';
import { Hero } from './hero';
import { HeroService } from './hero.service';
@@ -26,7 +26,7 @@ export class DashboardComponent implements OnInit {
}
gotoDetail(hero: Hero) {
- let link = ['HeroDetail', { id: hero.id }];
+ let link = ['/detail', hero.id];
this.router.navigate(link);
}
}
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 8da8978a08..85d722999e 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, Output } from '@angular/core';
+import { Component, EventEmitter, Input, OnInit, OnDestroy, Output } from '@angular/core';
// #enddocregion variables-imports
-import { RouteParams } from '@angular/router-deprecated';
+import { ActivatedRoute } from '@angular/router';
import { Hero } from './hero';
import { HeroService } from './hero.service';
@@ -14,31 +14,39 @@ import { HeroService } from './hero.service';
styleUrls: ['app/hero-detail.component.css']
})
// #docregion variables-imports
-export class HeroDetailComponent implements OnInit {
+export class HeroDetailComponent implements OnInit, OnDestroy {
@Input() hero: Hero;
@Output() close = new EventEmitter();
error: any;
+ sub: any;
navigated = false; // true if navigated here
// #enddocregion variables-imports
constructor(
private heroService: HeroService,
- private routeParams: RouteParams) {
+ private route: ActivatedRoute) {
}
// #docregion ngOnInit
ngOnInit() {
- if (this.routeParams.get('id') !== null) {
- let id = +this.routeParams.get('id');
- this.navigated = true;
- this.heroService.getHero(id)
- .then(hero => this.hero = hero);
- } else {
- this.navigated = false;
- this.hero = new Hero();
- }
+ this.sub = this.route.params.subscribe(params => {
+ if (params['id'] !== undefined) {
+ let id = +params['id'];
+ this.navigated = true;
+ this.heroService.getHero(id)
+ .then(hero => this.hero = hero);
+ } else {
+ this.navigated = false;
+ this.hero = new Hero();
+ }
+ });
}
// #enddocregion ngOnInit
+
+ ngOnDestroy() {
+ this.sub.unsubscribe();
+ }
+
// #docregion save
save() {
this.heroService
@@ -57,4 +65,3 @@ export class HeroDetailComponent implements OnInit {
}
// #enddocregion goBack
}
-
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 1573b96be6..3bf618f5bd 100644
--- a/public/docs/_examples/toh-6/ts/app/heroes.component.ts
+++ b/public/docs/_examples/toh-6/ts/app/heroes.component.ts
@@ -1,6 +1,6 @@
// #docregion
import { Component, OnInit } from '@angular/core';
-import { Router } from '@angular/router-deprecated';
+import { Router } from '@angular/router';
import { Hero } from './hero';
import { HeroService } from './hero.service';
@@ -68,6 +68,6 @@ export class HeroesComponent implements OnInit {
}
gotoDetail() {
- this.router.navigate(['HeroDetail', { id: this.selectedHero.id }]);
+ this.router.navigate(['/detail', this.selectedHero.id]);
}
}
diff --git a/public/docs/_examples/toh-6/ts/app/main.ts b/public/docs/_examples/toh-6/ts/app/main.ts
index 958b9a8c69..948e2ca5ba 100644
--- a/public/docs/_examples/toh-6/ts/app/main.ts
+++ b/public/docs/_examples/toh-6/ts/app/main.ts
@@ -11,16 +11,21 @@ import { InMemoryDataService } from './in-memory-data.service';
import { bootstrap } from '@angular/platform-browser-dynamic';
import { HTTP_PROVIDERS } from '@angular/http';
-import { AppComponent } from './app.component';
+import { AppComponent } from './app.component';
+import { APP_ROUTER_PROVIDERS } from './app.routes';
// #enddocregion v1, final
/*
// #docregion v1
-bootstrap(AppComponent, [ HTTP_PROVIDERS ]);
+bootstrap(AppComponent, [
+ APP_ROUTER_PROVIDERS,
+ HTTP_PROVIDERS
+]);
// #enddocregion v1
- */
+*/
// #docregion final
bootstrap(AppComponent, [
+ APP_ROUTER_PROVIDERS,
HTTP_PROVIDERS,
{ provide: XHRBackend, useClass: InMemoryBackendService }, // in-mem server
{ provide: SEED_DATA, useClass: InMemoryDataService } // in-mem server data
diff --git a/public/docs/_examples/user-input/dart/lib/app_component.dart b/public/docs/_examples/user-input/dart/lib/app_component.dart
index d86db43cb0..5f2c86f8d9 100644
--- a/public/docs/_examples/user-input/dart/lib/app_component.dart
+++ b/public/docs/_examples/user-input/dart/lib/app_component.dart
@@ -2,7 +2,7 @@
import 'package:angular2/core.dart';
import 'click_me_component.dart';
-import 'click_me_component_2.dart';
+import 'click_me2_component.dart';
import 'keyup_components.dart';
import 'little_tour_component.dart';
import 'loop_back_component.dart';
@@ -12,7 +12,7 @@ import 'loop_back_component.dart';
templateUrl: 'app_component.html',
directives: const [
ClickMeComponent,
- ClickMeComponent2,
+ ClickMe2Component,
KeyUpComponentV1,
KeyUpComponentV2,
KeyUpComponentV3,
diff --git a/public/docs/_examples/user-input/dart/lib/click_me2_component.dart b/public/docs/_examples/user-input/dart/lib/click_me2_component.dart
new file mode 100644
index 0000000000..3329a6692e
--- /dev/null
+++ b/public/docs/_examples/user-input/dart/lib/click_me2_component.dart
@@ -0,0 +1,18 @@
+// #docregion
+import 'package:angular2/core.dart';
+
+@Component(
+ selector: 'click-me2',
+ template: '''
+
+ {{clickMessage}}''')
+class ClickMe2Component {
+ String clickMessage = '';
+ int _clicks = 1;
+
+ void onClickMe2(dynamic event) {
+ var evtMsg =
+ event != null ? ' Event target is ' + event.target.tagName : '';
+ clickMessage = ('Click #${_clicks++}. ${evtMsg}');
+ }
+}
diff --git a/public/docs/_examples/user-input/dart/lib/click_me_component.dart b/public/docs/_examples/user-input/dart/lib/click_me_component.dart
index c1c7e19f93..c31d92e78b 100644
--- a/public/docs/_examples/user-input/dart/lib/click_me_component.dart
+++ b/public/docs/_examples/user-input/dart/lib/click_me_component.dart
@@ -1,3 +1,9 @@
+/* FOR DOCS ... MUST MATCH ClickMeComponent template
+// #docregion click-me-button
+
+// #enddocregion click-me-button
+*/
+
// #docregion
import 'package:angular2/core.dart';
@@ -5,15 +11,12 @@ import 'package:angular2/core.dart';
@Component(
selector: 'click-me',
template: '''
- // #docregion click-me-button
-
- // #enddocregion click-me-button
- {{clickMessage}}''')
+
+ {{clickMessage}}''')
class ClickMeComponent {
String clickMessage = '';
- onClickMe() {
+ void onClickMe() {
clickMessage = 'You are my hero!';
}
}
-// #enddocregion click-me-component
diff --git a/public/docs/_examples/user-input/dart/lib/click_me_component_2.dart b/public/docs/_examples/user-input/dart/lib/click_me_component_2.dart
deleted file mode 100644
index 8047b2280a..0000000000
--- a/public/docs/_examples/user-input/dart/lib/click_me_component_2.dart
+++ /dev/null
@@ -1,17 +0,0 @@
-// #docregion
-import 'package:angular2/core.dart';
-
-@Component(
- selector: 'click-me2',
- template: '''
- {{clickMessage}}''')
-class ClickMeComponent2 {
- String clickMessage = '';
- int clicks = 1;
-
- onClickMe2(dynamic event) {
- var evtMsg =
- event != null ? ' Event target is ' + event.target.tagName : '';
- clickMessage = ('Click #${clicks++}. ${evtMsg}');
- }
-}
diff --git a/public/docs/_examples/webpack/ts/package.webpack.json b/public/docs/_examples/webpack/ts/package.webpack.json
index 4064a86611..cc5948be7f 100644
--- a/public/docs/_examples/webpack/ts/package.webpack.json
+++ b/public/docs/_examples/webpack/ts/package.webpack.json
@@ -17,7 +17,7 @@
"@angular/http": "2.0.0-rc.3",
"@angular/platform-browser": "2.0.0-rc.3",
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
- "@angular/router-deprecated": "2.0.0-rc.2",
+ "@angular/router": "3.0.0-alpha.8",
"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/vendor.ts b/public/docs/_examples/webpack/ts/src/vendor.ts
index 1a45c91d46..ede1e2717d 100644
--- a/public/docs/_examples/webpack/ts/src/vendor.ts
+++ b/public/docs/_examples/webpack/ts/src/vendor.ts
@@ -5,7 +5,7 @@ import '@angular/platform-browser-dynamic';
import '@angular/core';
import '@angular/common';
import '@angular/http';
-import '@angular/router-deprecated';
+import '@angular/router';
// RxJS
import 'rxjs';
diff --git a/public/docs/dart/latest/guide/_data.json b/public/docs/dart/latest/guide/_data.json
index 7d25438019..eff9a7e77e 100644
--- a/public/docs/dart/latest/guide/_data.json
+++ b/public/docs/dart/latest/guide/_data.json
@@ -73,6 +73,12 @@
"intro": "Learn how to apply CSS styles to components."
},
+ "glossary": {
+ "title": "Glossary",
+ "intro": "Brief definitions of the most important words in the Angular 2 vocabulary",
+ "basics": true
+ },
+
"security": {
"title": "Security",
"intro": "Prevent security vulnerabilities"
diff --git a/public/docs/dart/latest/tutorial/toh-pt6.jade b/public/docs/dart/latest/tutorial/toh-pt6.jade
index 6778b6af28..694975a368 100644
--- a/public/docs/dart/latest/tutorial/toh-pt6.jade
+++ b/public/docs/dart/latest/tutorial/toh-pt6.jade
@@ -1 +1,141 @@
-!= partial("../../../_includes/_ts-temp")
+extends ../../../ts/latest/tutorial/toh-pt6.jade
+
+block includes
+ include ../_util-fns
+ - var _Http = 'BrowserClient';
+ - var _Angular_Http = 'Dart BrowserClient'
+ - var _httpUrl = 'https://pub.dartlang.org/packages/http'
+ - var _Angular_http_library = 'Dart http package'
+ - var _HTTP_PROVIDERS = 'BrowserClient'
+ - var _JSON_stringify = 'JSON.encode'
+
+block start-server-and-watch
+ :marked
+ ### Keep the app compiling and running
+ Open a terminal/console window.
+ Start the Dart compiler, watch for changes, and start our server by entering the command:
+
+ code-example(language="bash").
+ pub serve
+
+block http-library
+ :marked
+ We'll be using the !{_Angular_http_library}'s
+ `BrowserClient` class to communicate with a server.
+
+ ### Pubspec updates
+
+ We need to add a package dependency for the !{_Angular_http_library}.
+
+ We also need to add a `resolved_identifiers` entry, to inform the [angular2
+ transformer][ng2x] that we'll be using `BrowserClient`. (For an explanation of why
+ this extra configuration is needed, see the [HTTP client chapter][guide-http].) We'll
+ also need to use `Client` from http, so let's add that now as well.
+
+ Update `pubspec.yaml` to look like this (additions are highlighted):
+
+ [guide-http]: ../guide/server-communication.html#!#http-providers
+ [ng2x]: https://github.com/angular/angular/wiki/Angular-2-Dart-Transformer
+
+ - var stylePattern = { pnk: /(http.*|resolved_identifiers:|Browser.*|Client.*)/gm };
+ +makeExcerpt('pubspec.yaml', 'additions', null, stylePattern)
+
+block http-providers
+ :marked
+ Before our app can use `#{_Http}`, we have to register it as a service provider.
+
+block backend
+ :marked
+ We want to replace `BrowserClient`, the service that talks to the remote server,
+ with the in-memory web API service.
+ Our in-memory web API service, shown below, is implemented using the
+ `http` library `MockClient` class.
+ All `http` client implementations share a common `Client` interface, so
+ we'll have our app use the `Client` type so that we can freely switch between
+ implementations.
+
+block dont-be-distracted-by-backend-subst
+ //- N/A
+
+block get-heroes-details
+ :marked
+ To get the list of heroes, we first make an asynchronous call to
+ `http.get()`. Then we use the `_extractData` helper method to decode the
+ response payload (`body`).
+
+block hero-detail-comp-extra-imports-and-vars
+ //- N/A
+
+block hero-detail-comp-updates
+ :marked
+ ### Edit in the *HeroDetailComponent*
+
+ We already have `HeroDetailComponent` for viewing details about a specific hero.
+ Supporting edit functionality is a natural extension of the detail view,
+ so we are able to reuse `HeroDetailComponent` with a few tweaks.
+
+block hero-detail-comp-save-and-goback
+ //- N/A
+
+block add-new-hero-via-detail-comp
+ //- N/A
+
+block heroes-comp-directives
+ //- N/A
+
+block heroes-comp-add
+ //- N/A
+
+block review
+ //- Not showing animated gif due to differences between TS and Dart implementations.
+
+block filetree
+ .filetree
+ .file angular2-tour-of-heroes
+ .children
+ .file lib
+ .children
+ .file app_component.dart
+ .file app_component.css
+ .file dashboard_component.css
+ .file dashboard_component.html
+ .file dashboard_component.dart
+ .file hero.dart
+ .file hero_detail_component.css
+ .file hero_detail_component.html
+ .file hero_detail_component.dart
+ .file hero_service.dart
+ .file heroes_component.css
+ .file heroes_component.html
+ .file heroes_component.dart
+ .file main.dart
+ .file in_memory_data_service.dart (new)
+ .file web
+ .children
+ .file main.dart
+ .file index.html
+ .file sample.css (new)
+ .file styles.css
+ .file pubspec.yaml
+
+block file-summary
+ +makeTabs(
+ `toh-6/dart/lib/hero.dart,
+ toh-6/dart/lib/hero_detail_component.dart,
+ toh-6/dart/lib/hero_detail_component.html,
+ toh-6/dart/lib/hero_service.dart,
+ toh-6/dart/lib/heroes_component.dart,
+ toh-6/dart/web/index.html,
+ toh-6/dart/web/main.dart,
+ toh-6/dart/web/sample.css`,
+ `,,,,,,final,`,
+ `lib/hero.dart,
+ lib/hero_detail_component.dart,
+ lib/hero_detail_component.html,
+ lib/hero_service.dart,
+ lib/heroes_component.dart,
+ web/index.html,
+ web/main.dart,
+ web/sample.css`)
+
+ +makeExample('pubspec.yaml')
diff --git a/public/docs/js/latest/cookbook/ts-to-js.jade b/public/docs/js/latest/cookbook/ts-to-js.jade
index 93e3a9fb01..e7af4222b0 100644
--- a/public/docs/js/latest/cookbook/ts-to-js.jade
+++ b/public/docs/js/latest/cookbook/ts-to-js.jade
@@ -222,10 +222,11 @@ table(width="100%")
Most Angular 2 classes have one or more TypeScript *decorators*
attached to provide configuration and metadata. For example,
- a component must have a [`@Component`](../api/core/Component-decorator.html) decorator.
+ a component must have a [`@Component`](../api/core/index/Component-decorator.html) decorator.
大部分Angular 2中的类都会附加一个或多个TypeScript*装饰器*,用来提供配置和元数据。比如组件必须要有一个[`@Component`](../api/core/index/Component-decorator.html)装饰器。
+
+makeExample('cb-ts-to-js/ts/app/hero.component.ts', 'metadata')(format="." )
td
@@ -242,7 +243,7 @@ table(width="100%")
数组里的每一个条目都对应一个TypeScript装饰器。
In the following example, we create a new instance of `Component` that corresponds
- to the [`@Component`](../api/core/Component-decorator.html) TypeScript decorator.
+ to the [`@Component`](../api/core/index/Component-decorator.html) TypeScript decorator.
在下面的例子中,我们新建了一个`Component`的新实例,与[`@Component`](../api/core/index/Component-decorator.html)TypeScript装饰器相对应。
@@ -356,8 +357,8 @@ table(width="100%")
在TypeScript里,属性装饰器经常被用来为组件和指令提供额外的元数据。
For [inputs and outputs](../guide/template-syntax.html#inputs-outputs),
- we use [`@Input`](../api/core/Input-var.html)
- and [`@Output`](../api/core/Output-var.html) property decorators.
+ we use [`@Input`](../api/core/index/Input-var.html)
+ and [`@Output`](../api/core/index/Output-var.html) property decorators.
They may optionally specify input and output binding names if we want them to be
different from the class property names.
@@ -497,10 +498,10 @@ table(width="100%")
We can attach additional decorators to constructor parameters
to qualify the injection behavior. We can mark
- optional dependencies with the [`@Optional`](../api/core/Optional-var.html),
- inject host element attributes with [`@Attribute`](../api/core/Attribute-var.html),
- inject content child queries with [`@Query`](../api/core/Query-var.html)
- and inject view child queries with [`@ViewQuery`](../api/core/ViewQuery-var.html).
+ optional dependencies with the [`@Optional`](../api/core/index/Optional-var.html),
+ inject host element attributes with [`@Attribute`](../api/core/index/Attribute-var.html),
+ inject content child queries with [`@Query`](../api/core/index/Query-var.html)
+ and inject view child queries with [`@ViewQuery`](../api/core/index/ViewQuery-var.html).
我们可以往构造函数中附加额外的装饰器来调整注入行为。比如使用[`@Optional`](../api/core/index/Optional-var.html)来标记依赖是可选的,
用[`@Attribute`](../api/core/index/Attribute-var.html)来注入宿主元素的属性(Attribute),
@@ -533,8 +534,8 @@ table(width="100%")
:marked
We can apply other additional parameter decorators such as
- [`@Host`](../api/core/Host-var.html) and
- [`@SkipSelf`](../api/core/SkipSelf-var.html) in the same way -
+ [`@Host`](../api/core/index/Host-var.html) and
+ [`@SkipSelf`](../api/core/index/SkipSelf-var.html) in the same way -
by adding `new ng.core.Host()` or `ng.core.SkipSelf()` in the
parameters array.
@@ -565,9 +566,9 @@ table(width="100%")
### `Host`(宿主)装饰器
We can use host property decorators to bind a host element to a component or directive.
- The [`@HostBinding`](../api/core/HostBinding-var.html) decorator
+ The [`@HostBinding`](../api/core/index/HostBinding-var.html) decorator
binds host element properties to component data properties.
- The [`@HostListener`](../api/core/HostListener-var.html) decorator binds
+ The [`@HostListener`](../api/core/index/HostListener-var.html) decorator bimds
host element events to component event handlers.
我们可以使用宿主属性装饰器来把宿主元素绑定到组件或指令。
@@ -620,8 +621,8 @@ table(width="100%")
有好几个属性装饰器可以用来查询组件或指令的各级子节点。
- The [`@ViewChild`](../api/core/ViewChild-var.html) and
- [`@ViewChildren`](../api/core/ViewChildren-var.html) property decorators
+ The [`@ViewChild`](../api/core/index/ViewChild-var.html) and
+ [`@ViewChildren`](../api/core/index/ViewChildren-var.html) property decorators
allow a component to query instances of other components that are used in
its view.
@@ -633,8 +634,8 @@ table(width="100%")
+makeExample('cb-ts-to-js/ts/app/heroes-queries.component.ts', 'view')(format="." )
:marked
- The [`@ContentChild`](../api/core/ContentChild-var.html) and
- [`@ContentChildren`](../api/core/ContentChildren-var.html) property decorators
+ The [`@ContentChild`](../api/core/index/ContentChild-var.html) and
+ [`@ContentChildren`](../api/core/index/ContentChildren-var.html) property decorators
allow a component to query instances of other components that have been projected
into its view from elsewhere.
diff --git a/public/docs/js/latest/guide/_data.json b/public/docs/js/latest/guide/_data.json
index 567324b649..1e0d9aa221 100644
--- a/public/docs/js/latest/guide/_data.json
+++ b/public/docs/js/latest/guide/_data.json
@@ -73,6 +73,12 @@
"intro": "Learn how to apply CSS styles to components."
},
+ "glossary": {
+ "title": "Glossary",
+ "intro": "Brief definitions of the most important words in the Angular 2 vocabulary",
+ "basics": true
+ },
+
"hierarchical-dependency-injection": {
"title": "Hierarchical Dependency Injectors",
"navTitle": "Hierarchical Injectors",
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 3ddf9f4a2b..94d997b8bb 100644
--- a/public/docs/ts/latest/cookbook/a1-a2-quick-reference.jade
+++ b/public/docs/ts/latest/cookbook/a1-a2-quick-reference.jade
@@ -722,10 +722,10 @@ table(width="100%")
+makeExample('cb-a1-a2-quick-reference/ts/app/movie-list.component.html', 'ngSwitch')(format="." )
:marked
In Angular 2, the `ngSwitch` directive works similarly.
- It displays an element whose `*ngSwitchWhen` matches the current `ngSwitch` expression value.
+ It displays an element whose `*ngSwitchCase` matches the current `ngSwitch` expression value.
在Angular 2中,`ngSwitch`指令的工作方式与此类似。
- 它会显示那个与`ngSwitch`表达式的当前值匹配的那个`*ngSwitchWhen`所在的元素。
+ 它会显示那个与`ngSwitch`表达式的当前值匹配的那个`*ngSwitchCase`所在的元素。
In this example, if `favoriteHero` is not set, the `ngSwitch` value is `null`
and we see the `*ngSwitchDefault` paragraph, "Please enter ...".
@@ -739,9 +739,9 @@ table(width="100%")
如果该方法返回`true`,我们就会看到“Excellent choice!”。
如果该方法返回`false`,我们就会看到“No movie, sorry!”。
- The (*) before `ngSwitchWhen` and `ngSwitchDefault` is required in this example.
+ The (*) before `ngSwitchCase` and `ngSwitchDefault` is required in this example.
- 在这个例子中,`ngSwitchWhen`和`ngSwitchDefault`前面的星号(*)是必须的。
+ 在这个例子中,`ngSwitchCase`和`ngSwitchDefault`前面的星号(*)是必须的。
For more information on the ngSwitch directive see [Template Syntax](../guide/template-syntax.html#ngSwitch).
diff --git a/public/docs/ts/latest/guide/_data.json b/public/docs/ts/latest/guide/_data.json
index c2e1ccbfa4..07277ad84c 100644
--- a/public/docs/ts/latest/guide/_data.json
+++ b/public/docs/ts/latest/guide/_data.json
@@ -86,6 +86,12 @@
"intro": "学习如何给组件应用CSS样式。"
},
+ "glossary": {
+ "title": "Glossary",
+ "intro": "Brief definitions of the most important words in the Angular 2 vocabulary",
+ "basics": true
+ },
+
"hierarchical-dependency-injection": {
"title": "多级依赖注入器",
"navTitle": "多级注入器",
diff --git a/public/docs/ts/latest/guide/animations.jade b/public/docs/ts/latest/guide/animations.jade
index 9578809e5f..0793559c9d 100644
--- a/public/docs/ts/latest/guide/animations.jade
+++ b/public/docs/ts/latest/guide/animations.jade
@@ -107,7 +107,7 @@ figure
:marked
With these we can now define an *animation trigger* called `heroState` in the component
metadata. It has animated transitions between two states: `active` and `inactive`. When a
- hero is active, we display a the element in slightly larger size and lighter color.
+ hero is active, we display the element in a slightly larger size and lighter color.
通过这些,可以在组件元数据中定义一个名叫`heroState`的*动画触发器*。它在两个状态`active`和`inactive`之间进行转场。
当英雄处于激活状态时,它会把该元素显示得稍微大一点、亮一点。
diff --git a/public/docs/ts/latest/guide/architecture.jade b/public/docs/ts/latest/guide/architecture.jade
index ae10bd72e4..437c22dcbb 100644
--- a/public/docs/ts/latest/guide/architecture.jade
+++ b/public/docs/ts/latest/guide/architecture.jade
@@ -727,10 +727,10 @@ figure
+makeExample('architecture/ts/app/logger.service.ts', 'class', 'app/logger.service.ts (只有类)')(format=".")
:marked
Here's a `HeroService` that fetches heroes and returns them in a resolved [promise](http://exploringjs.com/es6/ch_promises.html).
- The `HeroService` depends on the `LoggerService` and another `BackendService` that handles the server communication grunt work.
+ The `HeroService` depends on the `Logger` service and another `BackendService` that handles the server communication grunt work.
下面是`HeroService`类,用于获取英雄数据,并通过一个已解析的[承诺Promise](http://exploringjs.com/es6/ch_promises.html)返回它们。
- `HeroService`还依赖于`LoggerService`和另一个用来处理服务器通讯工作的`BackendService`。
+ `HeroService`还依赖于`Logger`服务和另一个用来处理服务器通讯工作的`BackendService`服务。
+makeExample('architecture/ts/app/hero.service.ts', 'class', 'app/hero.service.ts (只有类)')(format=".")
:marked
diff --git a/public/docs/ts/latest/guide/attribute-directives.jade b/public/docs/ts/latest/guide/attribute-directives.jade
index 8385384ee7..3ff036869c 100644
--- a/public/docs/ts/latest/guide/attribute-directives.jade
+++ b/public/docs/ts/latest/guide/attribute-directives.jade
@@ -108,7 +108,8 @@ include ../_quickstart_repo
Create the following source file in the indicated folder with the given code:
在指定的文件夹下创建下列源码文件:
-+makeExample('attribute-directives/ts/app/highlight.directive.1.ts', null, 'app/highlight.directive.ts')
+
++makeExample('app/highlight.directive.1.ts')
block highlight-directive-1
:marked
@@ -165,7 +166,7 @@ block highlight-directive-1
我们需要一个自己的前缀,最好短点儿,目前用的这个`my`前缀就不错。
p
- | After the `@Directive` metadata comes the directive's controller class, which contains the logic for the directive.
+ | After the #[code @Directive] metadata comes the directive's controller class, which contains the logic for the directive.
+ifDocsFor('ts')
| We export `HighlightDirective` to make it accessible to other components.
p
@@ -270,6 +271,7 @@ figure.image-display
a#respond-to-user
:marked
## Respond to user action
+
## 响应用户的操作
We are not satisfied to simply set an element color.
@@ -283,20 +285,23 @@ a#respond-to-user
We'll need to
我们需要:
+
1. detect when the user hovers into and out of the element,
1. 检测用户的鼠标啥时候进入和离开这个元素。
2. respond to those actions by setting and clearing the highlight color, respectively.
2. 通过设置和清除高亮色来响应这些操作。
- We use the `@HostListener` decorator on a method which is called when the event is raised.
+ We apply the `@HostListener` !{_decorator} to methods which are called when an event is raised.
从事件检测开始吧。
把`host`属性加入指令的元数据中,并给它一个配置对象,用来指定两个鼠标事件,并在它们被触发时,调用指令中的方法:
+
+makeExample('attribute-directives/ts/app/highlight.directive.2.ts','host')(format=".")
.l-sub-section
+
:marked
- The `@HostListener` decorator refers to the DOM element that hosts our attribute directive, the `
` in our case.
+ The `@HostListener` !{_decorator} refers to the DOM element that hosts our attribute directive, the `
` in our case.
`@HostListener`装饰器引用的是我们这个属性型指令的宿主元素,在这个例子中就是`
`。
@@ -312,14 +317,17 @@ a#respond-to-user
1. We'd be talking to DOM API directly which, we learned, is something to avoid.
1. 必须直接和DOM API打交道,但正如我们学过的那样,应该避免这样做。
- Let's roll with the `@HostListener` decorator.
+ Let's roll with the `@HostListener` !{_decorator}.
我们还是围绕`@HostListener`装饰器来吧。
+
:marked
Now we implement the two mouse event handlers:
现在,我们实现那两个鼠标事件处理器:
+
+makeExample('attribute-directives/ts/app/highlight.directive.2.ts','mouse-methods')(format=".")
+
:marked
Notice that they delegate to a helper method that sets the color via a private local variable, `#{_priv}el`.
We revise the constructor to capture the `ElementRef.nativeElement` in this variable.
@@ -328,11 +336,14 @@ a#respond-to-user
我们要修改构造函数,来把`ElementRef.nativeElement`存进这个私有变量。
+makeExample('attribute-directives/ts/app/highlight.directive.2.ts','ctor')(format=".")
+
:marked
Here's the updated directive:
这里是更新过的指令:
-+makeExample('attribute-directives/ts/app/highlight.directive.2.ts',null, 'app/highlight.directive.ts')
+
++makeExample('app/highlight.directive.2.ts')
+
:marked
We run the app and confirm that the background color appears as we move the mouse over the `p` and
disappears as we move out.
@@ -361,7 +372,8 @@ a#bindings
这里是该类的最终版:
-+makeExample('attribute-directives/ts/app/highlight.directive.ts', 'class-1', 'app/highlight.directive.ts (class only)')
++makeExcerpt('app/highlight.directive.ts', 'class')
+
a#input
:marked
The new `highlightColor` property is called an *input* property because data flows from the binding expression into our directive.
@@ -369,7 +381,9 @@ a#input
新的`highlightColor`属性被称为“输入”属性,这是因为数据流是从绑定表达式到这个指令的。
注意,在定义这个属性的时候,我们调用了`@Input()`#{_decoratorCn}。
-+makeExample('attribute-directives/ts/app/highlight.directive.ts', 'color')
+
++makeExcerpt('app/highlight.directive.ts', 'color')
+
:marked
`@Input` adds metadata to the class that makes the `highlightColor` property available for
property binding under the `myHighlight` alias.
@@ -393,7 +407,7 @@ a#input
我们可以通过把属性名改为`myHighlight`来解决这个矛盾,就像这样:
- +makeExample('attribute-directives/ts/app/highlight.directive.ts', 'highlight')
+ +makeExcerpt('app/highlight.directive.ts', 'highlight', '')
:marked
Maybe we don't want that property name inside the directive perhaps because it
doesn't express our intention well.
@@ -402,7 +416,9 @@ a#input
但我们可能在指令中不想要那样一个属性名,因为它不能很好的表示我们的意图。
可以通过把`myHighlight`传给`@Input`#{_decoratorCn}来把这个属性名作为`highlightColor`属性的别名。
- +makeExample('attribute-directives/ts/app/highlight.directive.ts', 'color')
+
+ +makeExcerpt('app/highlight.directive.ts', 'color', '')
+
:marked
Now that we're getting the highlight color as an input, we modify the `onMouseEnter()` method to use
it instead of the hard-coded color name.
@@ -411,7 +427,9 @@ a#input
现在,通过输入型属性得到了高亮的颜色,然后修改`onMouseEnter()`来使用它代替硬编码的那个颜色名。
我们还把红色定义为默认颜色,以便在用户忘了绑定颜色时作为备用。
-+makeExample('attribute-directives/ts/app/highlight.directive.ts', 'mouse-enter')
+
++makeExcerpt('attribute-directives/ts/app/highlight.directive.ts', 'mouse-enter', '')
+
:marked
Now we'll update our `AppComponent` template to let
users pick the highlight color and bind their choice to our directive.
@@ -422,7 +440,7 @@ a#input
这里是更新后的模板:
-+makeExample('attribute-directives/ts/app/app.component.html', 'v2')
++makeExcerpt('attribute-directives/ts/app/app.component.html', 'v2', '')
.l-sub-section
:marked
diff --git a/public/docs/ts/latest/guide/dependency-injection.jade b/public/docs/ts/latest/guide/dependency-injection.jade
index c2fe895c5d..86abbfbd51 100644
--- a/public/docs/ts/latest/guide/dependency-injection.jade
+++ b/public/docs/ts/latest/guide/dependency-injection.jade
@@ -1172,7 +1172,7 @@ block what-should-we-use-as-token
// end Typescript only
//- FIXME simplify once APIs are defined for Dart.
-- var opaquetoken = _docsFor == 'dart' ? 'OpaqueToken' : 'OpaqueToken'
+- var opaquetoken = _docsFor == 'dart' ? 'OpaqueToken' : 'OpaqueToken'
:marked
### OpaqueToken
diff --git a/public/docs/ts/latest/guide/forms.jade b/public/docs/ts/latest/guide/forms.jade
index b44136e48e..c5fe5af688 100644
--- a/public/docs/ts/latest/guide/forms.jade
+++ b/public/docs/ts/latest/guide/forms.jade
@@ -2,11 +2,13 @@ include ../_util-fns
.alert.is-important
:marked
- This guide is using the new forms API.
+ 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).
这份指南使用新的表单API。
- The old forms API is deprecated, but we still maintain a separate version of the guide using the deprecated forms API here.
+ The old forms API is deprecated, but we still maintain a separate version of the guide using
+ the deprecated forms API here.
旧的表单API已经废弃了,但是在本指南中仍然维护着一个独立的版本,它使用已废弃的表单API,参见这里。
@@ -883,7 +885,7 @@ figure.image-display
.l-sub-section
:marked
Why "ngModel"?
- A directive's [exportAs](../api/core/DirectiveMetadata-class.html#!#exportAs) property
+ A directive's [exportAs](../api/core/index/DirectiveMetadata-class.html#!#exportAs-anchor) property
tells Angular how to link the reference variable to the directive.
We set `name` to `ngModel` because the `ngModel` directive's `exportAs` property happens to be "ngModel".
diff --git a/public/docs/ts/latest/guide/lifecycle-hooks.jade b/public/docs/ts/latest/guide/lifecycle-hooks.jade
index a052341e31..f7a6238fd3 100644
--- a/public/docs/ts/latest/guide/lifecycle-hooks.jade
+++ b/public/docs/ts/latest/guide/lifecycle-hooks.jade
@@ -657,7 +657,7 @@ figure.image-display
+makeExample('lifecycle-hooks/ts/app/on-changes.component.ts', 'ng-on-changes', 'OnChangesComponent (ngOnChanges)')(format=".")
:marked
The `ngOnChanges` method takes an object that maps each changed property name to a
- [SimpleChange](../api/core/SimpleChange-class.html) object with the current and previous property values.
+ [SimpleChange](../api/core/index/SimpleChange-class.html) object with the current and previous property values.
We iterate over the changed properties and log them.
`ngOnChanges`方法获取了一个对象,它把每个发生变化的属性名都映射到了一个[SimpleChange](../api/core/index/SimpleChange-class.html)对象,
@@ -754,7 +754,7 @@ figure.image-display
.l-sub-section
:marked
We also see that the `ngOnChanges` method is called in contradiction of the
- [incorrect API documentation](../api/core/DoCheck-interface.html).
+ [incorrect API documentation](../api/core/index/DoCheck-class.html).
我们还看到,`ngOnChanges`方法的调用方式与[API文档](../api/core/index/DoCheck-interface.html)中是不一样的,这是因为API文档过时了。
(译注:这是经过与官方开发组沟通得到的消息,由于代码快速迭代,因此API文档现在的更新不够及时,将来会进行一次系统的梳理和更正)
@@ -778,7 +778,7 @@ figure.image-display
:marked
The following hooks take action based on changing values *within the child view*
which we can only reach by querying for the child view via the property decorated with
- [@ViewChild](../api/core/ViewChild-var.html).
+ [@ViewChild](../api/core/index/ViewChild-var.html).
下列钩子基于*子视图中*的每一次数据变更采取行动,我们只能通过带[@ViewChild](../api/core/index/ViewChild-var.html)装饰器的属性来访问子视图。
@@ -907,7 +907,7 @@ figure.image-display
The following *AfterContent* hooks take action based on changing values in a *content child*
which we can only reach by querying for it via the property decorated with
- [@ContentChild](../api/core/ContentChild-var.html).
+ [@ContentChild](../api/core/index/ContentChild-var.html).
下列*AfterContent*钩子基于*子级内容*中值的变化而采取相应的行动,这里我们只能通过带有[@ContentChild](../api/core/index/ContentChild-var.html)装饰器的属性来查询到“子级内容”。
diff --git a/public/docs/ts/latest/guide/pipes.jade b/public/docs/ts/latest/guide/pipes.jade
index 0f8148af7a..5bef166edc 100644
--- a/public/docs/ts/latest/guide/pipes.jade
+++ b/public/docs/ts/latest/guide/pipes.jade
@@ -402,7 +402,7 @@ figure.image-display
More often we don't know when the data have changed,
especially in applications that mutate data in many ways,
perhaps in application locations far away.
- A component is such an application usually can't know about those changes.
+ A component in such an application usually can't know about those changes.
Moreover, it's unwise to distort our component design to accommodate a pipe.
We strive as much as possible to keep the component class independent of the HTML.
The component should be unaware of pipes.
diff --git a/public/docs/ts/latest/guide/router-deprecated.jade b/public/docs/ts/latest/guide/router-deprecated.jade
index 5e34f2fb1c..d55523a082 100644
--- a/public/docs/ts/latest/guide/router-deprecated.jade
+++ b/public/docs/ts/latest/guide/router-deprecated.jade
@@ -892,7 +892,7 @@ code-example(format="").
## Router Lifecycle Hooks
Angular components have [lifecycle hooks](lifecycle-hooks.html). For example, Angular calls the hook methods of the
- [OnInit](../api/core/OnInit-interface.html) and [OnDestroy](../api/core/OnDestroy-interface.html)
+ [OnInit](../api/core/index/OnInit-class.html) and [OnDestroy](../api/core/index/OnDestroy-class.html)
interfaces when it creates and destroys components.
The router also has hooks for *its* lifecycle such as
@@ -1369,8 +1369,8 @@ code-example(format="." language="bash").
How do we ensure that happens if not in the constructor?
Angular detects when a component has certain lifecycle methods like
- [ngOnInit](../api/core/OnInit-interface.html) and
- [ngOnDestroy](../api/core/OnDestroy-interface.html) and calls
+ [ngOnInit](../api/core/index/OnInit-class.html) and
+ [ngOnDestroy](../api/core/index/OnDestroy-class.html) and calls
them
at the appropriate moment.
diff --git a/public/docs/ts/latest/guide/router.jade b/public/docs/ts/latest/guide/router.jade
index a9dab49dc0..66c88998ab 100644
--- a/public/docs/ts/latest/guide/router.jade
+++ b/public/docs/ts/latest/guide/router.jade
@@ -413,9 +413,9 @@ table
p 路由组件
td
- p An Angular component with a *RouterOutlet* that displays views based on router navigations.
+ p An Angular component with a RouterOutlet that displays views based on router navigations.
- p 一个带有*RouterOutlet*的Angular组件,它根据路由器的导航来显示相应的视图。
+ p 一个带有RouterOutlet的Angular组件,它根据路由器的导航来显示相应的视图。
:marked
We've barely touched the surface of the router and its capabilities.
@@ -1996,7 +1996,7 @@ h2#guards 路由守卫
守卫可能会向用户问一个问题、把更改保存到服务器,或者获取新数据,而这些都是异步操作。
Accordingly, a routing guard can return an `Observable` and the
- router will wait for the observable to resolve to `true` or `false.
+ router will wait for the observable to resolve to `true` or `false`.
因此,路由的守卫可以返回一个`Observable`,并且路由器会等待这个可观察对象被解析为`true`或`false`。
@@ -2907,8 +2907,8 @@ code-example(format="." language="bash").
然而我们还是需要该类的实例在创建完之后尽快从`HeroService`中获取英雄数据。如果不能放在构造函数中又该怎么办?
Angular detects when a component has certain lifecycle methods like
- [ngOnInit](../api/core/OnInit-interface.html) and
- [ngOnDestroy](../api/core/OnDestroy-interface.html) and calls
+ [ngOnInit](../api/core/index/OnInit-class.html) and
+ [ngOnDestroy](../api/core/index/OnDestroy-class.html) and calls
them
at the appropriate moment.
@@ -3079,7 +3079,7 @@ code-example(format=".", language="bash").
.l-sub-section
:marked
- Learn about the [APP_BASE_HREF](../api/router/APP_BASE_HREF-let.html)
+ Learn about the [APP_BASE_HREF](../api/common/index/APP_BASE_HREF-let.html)
in the API Guide.
你可以到API指南中学习关于[APP_BASE_HREF](../api/router/APP_BASE_HREF-let.html)的更多知识。
diff --git a/public/docs/ts/latest/guide/server-communication.jade b/public/docs/ts/latest/guide/server-communication.jade
index a82c6ab0c0..698d21761c 100644
--- a/public/docs/ts/latest/guide/server-communication.jade
+++ b/public/docs/ts/latest/guide/server-communication.jade
@@ -147,9 +147,10 @@ block system-config-of-http
当我们从`@angular/http`模块中导入服务时,SystemJS知道该如何从!{_Angular_http_libraryCn}中加载它们,这是因为我们已经在`system.config`文件中注册过这个模块名。
:marked
- Before we can use the `#{_Http}` client , we'll have to register it as a service provider with the Dependency Injection system.
+ Before we can use the `#{_Http}` client , we'll have to register it as a service provider with the Dependency Injection system.
- 要想使用`#{_Http}`客户端,我们得先通过依赖注入系统把它注册成一个服务供应商。
+ 要想使用`#{_Http}`客户端,我们得先通过依赖注入系统把它注册成一个服务供应商。
+
.l-sub-section
:marked
Learn about providers in the [Dependency Injection](dependency-injection.html) chapter.
diff --git a/public/docs/ts/latest/guide/style-guide.jade b/public/docs/ts/latest/guide/style-guide.jade
index daff04baf1..cf8d731227 100644
--- a/public/docs/ts/latest/guide/style-guide.jade
+++ b/public/docs/ts/latest/guide/style-guide.jade
@@ -2028,7 +2028,7 @@ a(href="#toc") 回到顶部
.s-rule.do
:marked
- **Do** use [`@Input`](https://angular.io/docs/ts/latest/api/core/Input-var.html) and [`@Output`](https://angular.io/docs/ts/latest/api/core/Output-var.html) instead of the `inputs` and `outputs` properties of the [`@Directive`](https://angular.io/docs/ts/latest/api/core/Directive-decorator.html) and [`@Component`](https://angular.io/docs/ts/latest/api/core/Component-decorator.html) decorators:
+ **Do** use [`@Input`](https://angular.io/docs/ts/latest/api/core/index/Input-var.html) and [`@Output`](https://angular.io/docs/ts/latest/api/core/index/Output-var.html) instead of the `inputs` and `outputs` properties of the [`@Directive`](https://angular.io/docs/ts/latest/api/core/index/Directive-decorator.html) and [`@Component`](https://angular.io/docs/ts/latest/api/core/index/Component-decorator.html) decorators:
**坚持**使用[`@Input`](https://angular.io/docs/ts/latest/api/core/Input-var.html)和[`@Output`](https://angular.io/docs/ts/latest/api/core/Output-var.html), 而非[`@Directive`](https://angular.io/docs/ts/latest/api/core/Directive-decorator.html) 和 [`@Component`](https://angular.io/docs/ts/latest/api/core/Component-decorator.html) 装饰器里面的`inputs`和`outputs`属性。
@@ -2046,7 +2046,7 @@ a(href="#toc") 回到顶部
.s-why
:marked
- **Why?** If we ever need to rename the property or event name associated to [`@Input`](https://angular.io/docs/ts/latest/api/core/Input-var.html) or [`@Output`](https://angular.io/docs/ts/latest/api/core/Output-var.html) we can modify it on a single place.
+ **Why?** If we ever need to rename the property or event name associated to [`@Input`](https://angular.io/docs/ts/latest/api/core/index/Input-var.html) or [`@Output`](https://angular.io/docs/ts/latest/api/core/index/Output-var.html) we can modify it on a single place.
**为何?**如果我们需要重命名[`@Input`](https://angular.io/docs/ts/latest/api/core/Input-var.html) 或 [`@Output`](https://angular.io/docs/ts/latest/api/core/Output-var.html)关的属性或者事件,我们可以在一个地方修改。
diff --git a/public/docs/ts/latest/guide/template-syntax.jade b/public/docs/ts/latest/guide/template-syntax.jade
index b385b18f0e..da855fb0c2 100644
--- a/public/docs/ts/latest/guide/template-syntax.jade
+++ b/public/docs/ts/latest/guide/template-syntax.jade
@@ -836,8 +836,8 @@ table
If we must read a target element property or call one of its methods,
we'll need a different technique.
See the API reference for
- [viewChild](../api/core/ViewChild-var.html) and
- [contentChild](../api/core/ContentChild-var.html).
+ [viewChild](../api/core/index/ViewChild-var.html) and
+ [contentChild](../api/core/index/ContentChild-var.html).
如果我们不得不读取目标元素上的属性或调用它的某个方法,我们得用另一种技术。
参见API参考手册中的[viewChild](../api/core/index/ViewChild-var.html)和
@@ -1310,7 +1310,7 @@ block style-property-name-dart-diff
### Custom events with EventEmitter
### 使用EventEmitter实现自定义事件
- Directives typically raise custom events with an Angular [EventEmitter](../api/core/EventEmitter-class.html).
+ Directives typically raise custom events with an Angular [EventEmitter](../api/core/index/EventEmitter-class.html).
A directive creates an `EventEmitter` and exposes it as a property.
The directive calls `EventEmitter.emit(payload)` to fire an event, passing in a message payload that can be anything.
Parent directives listen for the event by binding to this property and accessing the payload through the `$event` object.
@@ -1456,7 +1456,7 @@ block style-property-name-dart-diff
The `ngModel` input property sets the element's value property and the `ngModelChange` output property
listens for changes to the element's value.
The details are specific to each kind of element and therefore the `NgModel` directive only works for elements,
- such as the input text box, that are supported by a [ControlValueAccessor](../api/common/ControlValueAccessor-interface.html).
+ such as the input text box, that are supported by a [ControlValueAccessor](../api/common/index/ControlValueAccessor-interface.html).
We can't apply `[(ngModel)]` to our custom components until we write a suitable *value accessor*,
a technique that is beyond the scope of this chapter.
@@ -1738,8 +1738,8 @@ block dart-no-truthy-falsey
这里有三个相互合作的指令:
1. `ngSwitch`: bound to an expression that returns the switch value
1. `ngSwitch`:绑定到一个返回开关值的表达式
- 1. `ngSwitchWhen`: bound to an expression returning a match value
- 1. `ngSwitchWhen`:绑定到一个返回匹配值的表达式
+ 1. `ngSwitchCase`: bound to an expression returning a match value
+ 1. `ngSwitchCase`:绑定到一个返回匹配值的表达式
1. `ngSwitchDefault`: a marker attribute on the default element
1. `ngSwitchDefault`:一个用于标记出默认元素的Attribute
@@ -1749,10 +1749,10 @@ block dart-no-truthy-falsey
**不要**在`ngSwitch`的前面放星号(`*`),而应该用属性绑定。
- **Do** put the asterisk (`*`) in front of `ngSwitchWhen` and `ngSwitchDefault`.
+ **Do** put the asterisk (`*`) in front of `ngSwitchCase` and `ngSwitchDefault`.
For more information, see [\* and <template>](#star-template).
- **要**把星号(`*`)放在`ngSwitchWhen`和`ngSwitchDefault`的前面。
+ **要**把星号(`*`)放在`ngSwitchCase`和`ngSwitchDefault`的前面。
要了解更多信息,参见[\*与<template>](#star-template)。
@@ -1852,7 +1852,7 @@ block dart-no-truthy-falsey
+makeExample('template-syntax/ts/app/app.component.html', 'NgFor-3')(format=".")
.l-sub-section
:marked
- Learn about other special *index-like* values such as `last`, `even`, and `odd` in the [NgFor API reference](../api/common/NgFor-directive.html).
+ Learn about other special *index-like* values such as `last`, `even`, and `odd` in the [NgFor API reference](../api/common/index/NgFor-directive.html).
要学习更多的*类似index*的值,例如`last`、`even`和`odd`,请参阅[NgFor API 参考](../api/common/index/NgFor-directive.html)。
@@ -1983,13 +1983,13 @@ block remember-the-brackets
### Expanding `*ngSwitch`
### 展开`*ngSwitch`
A similar transformation applies to `*ngSwitch`. We can de-sugar the syntax ourselves.
- Here's an example, first with `*ngSwitchWhen` and `*ngSwitchDefault` and then again with `` tags:
+ Here's an example, first with `*ngSwitchCase` and `*ngSwitchDefault` and then again with `` tags:
类似的转换也作用于`*ngSwitch`上。我们可以自己解开这个语法糖。
- 这里是一个例子,首先是`*ngSwitchWhen`和`*ngSwitchDefault`,然后再解出``标签:
+ 这里是一个例子,首先是`*ngSwitchCase`和`*ngSwitchDefault`,然后再解出``标签:
+makeExample('template-syntax/ts/app/app.component.html', 'NgSwitch-expanded')(format=".")
:marked
- The `*ngSwitchWhen` and `*ngSwitchDefault` expand in exactly the same manner as `*ngIf`,
+ The `*ngSwitchCase` and `*ngSwitchDefault` expand in exactly the same manner as `*ngIf`,
wrapping their former elements in `` tags.
`*ngSwitchWhen`和`*ngSwitchDefault`用和`*ngIf`完全相同的方式展开,把它们以前的元素包裹在``标签中。
@@ -2000,13 +2000,14 @@ block remember-the-brackets
现在,我们应该明白为什么`ngSwitch`本身不能用星号(*)前缀的原因了吧?
它没有定义内容,它的工作是控制一组模板。
- In this case, it governs two sets of `NgSwitchWhen` and `NgSwitchDefault` directives.
+ In this case, it governs two sets of `NgSwitchCase` and `NgSwitchDefault` directives.
We should expect it to display the values of the selected template twice,
once for the (*) prefixed version and once for the expanded template version.
That's exactly what we see in this example:
- 上面这种情况下,它管理两组`NgSwitchWhen`和`NgSwitchDefault`指令,一次是(*)前缀的版本,一次是展开模板后的版本。
+ 上面这种情况下,它管理两组`NgSwitchCase`和`NgSwitchDefault`指令,一次是(*)前缀的版本,一次是展开模板后的版本。
我们也期待它显示所选模板的值两次。这正是我们在这个例子中看到的:
+
figure.image-display
img(src='/resources/images/devguide/template-syntax/ng-switch-anim.gif' alt="NgSwitch")
:marked
diff --git a/public/docs/ts/latest/guide/upgrade.jade b/public/docs/ts/latest/guide/upgrade.jade
index 29cd99a140..67b1b42d71 100644
--- a/public/docs/ts/latest/guide/upgrade.jade
+++ b/public/docs/ts/latest/guide/upgrade.jade
@@ -571,7 +571,7 @@ figure.image-display
In Angular 2 things are different. While change detection still
occurs after every event, no one needs to call `scope.$apply()` for
that to happen. This is because all Angular 2 code runs inside something
- called the [Angular zone](../api/core/NgZone-class.html). Angular always
+ called the [Angular zone](../api/core/index/NgZone-class.html). Angular always
knows when the code finishes, so it also knows when it should kick off
change detection. The code itself doesn't have to call `scope.$apply()`
or anything like it.
@@ -617,7 +617,7 @@ figure.image-display
the component's inputs will be watched using Angular 1 change detection.
When those inputs change, the corresponding properties in the component
are set. We can also hook into the changes by implementing the
- [OnChanges](../api/core/OnChanges-interface.html) interface in the component,
+ [OnChanges](../api/core/index/OnChanges-class.html) interface in the component,
just like we could if it hadn't been downgraded.
当我们降级一个Angular 2组件,然后把它用于Angular 1中时,组件的输入属性就会被Angular 1的变更检测体系监视起来。
diff --git a/public/docs/ts/latest/testing/first-app-tests.jade b/public/docs/ts/latest/testing/first-app-tests.jade
index c35e871cda..b891f90973 100644
--- a/public/docs/ts/latest/testing/first-app-tests.jade
+++ b/public/docs/ts/latest/testing/first-app-tests.jade
@@ -340,7 +340,7 @@ figure.image-display
### 异步System.import
- The call to `System.import` shouldn't surprise us but it's asynchronous nature might.
+ The call to `System.import` shouldn't surprise us but its asynchronous nature might.
If we ponder this for a moment, we realize that it must be asynchronous because
System.js may have to fetch the corresponding JavaScript file from the server.
Accordingly, `System.import` returns a promise and we must wait for that promise to resolve.
diff --git a/public/docs/ts/latest/tutorial/toh-pt5.jade b/public/docs/ts/latest/tutorial/toh-pt5.jade
index 5bd8e5a252..fb63694e9a 100644
--- a/public/docs/ts/latest/tutorial/toh-pt5.jade
+++ b/public/docs/ts/latest/tutorial/toh-pt5.jade
@@ -5,7 +5,7 @@ include ../_util-fns
# 应用中的路由
- We received new requirements for our Tour of Heroes application:
+ We received new requirements for our Tour of Heroes application:
我们收到了一份《英雄指南》的新需求:
@@ -21,10 +21,10 @@ include ../_util-fns
* 无论在哪个视图中点击一个英雄,都会导航到该英雄的详情页。
- * Clicking a *deep link* in an email opens the detail view for a particular hero;
+ * Clicking a *deep link* in an email opens the detail view for a particular hero;
* 在邮件中点击一个*深链接*,会直接打开一个特定英雄的详情视图。
-
+
When we’re done, users will be able to navigate the app like this:
完成时,用户就能像这样浏览一个应用:
@@ -38,10 +38,10 @@ figure.image-display
.l-sub-section
:marked
- The [Routing and Navigation](../guide/router-deprecated.html) chapter covers the router in more detail
- than we will in this tour.
+ The [Routing and Navigation](../guide/router.html) chapter covers the router in more detail
+ than we will in this tutorial.
- [路由与导航](../guide/router-deprecated.html)一章覆盖了比该教程中更详细的路由知识。
+ [路由与导航](../guide/router.html)一章覆盖了比该教程中更详细的路由知识。
p Run the #[+liveExampleLink2('', 'toh-5')] for this part.
@@ -50,7 +50,7 @@ p 运行这部分的#[+liveExampleLink2('在线例子', 'toh-5')]。
.l-sub-section
img(src='/resources/images/devguide/plunker-separate-window-button.png' alt="弹出窗口" align="right" style="margin-right:-20px")
:marked
- To see the URL changes in the browser address bar,
+ To see the URL changes in the browser address bar,
pop out the preview window by clicking the blue 'X' button in the upper right corner:
注意看浏览器地址栏中的URL变化,点击右上角的蓝色'X'按钮,弹出预览窗口。
@@ -61,7 +61,7 @@ p 运行这部分的#[+liveExampleLink2('在线例子', 'toh-5')]。
## 我们在哪儿
- Before we continue with our Tour of Heroes, let’s verify that we have the following structure after adding our hero service
+ Before we continue with our Tour of Heroes, let’s verify that we have the following structure after adding our hero service
and hero detail component. If not, we’ll need to go back and follow the previous chapters.
在继续《英雄指南》之前,先来检查一下,在添加了英雄服务和英雄详情组件之后,你是否已经有了如下目录结构。如果没有,你得先回上一章,再照做一遍。
@@ -78,7 +78,7 @@ p 运行这部分的#[+liveExampleLink2('在线例子', 'toh-5')]。
.file main.ts
.file mock-heroes.ts
.file node_modules ...
- .file typings ...
+ .file typings ...
.file index.html
.file package.json
.file styles.css
@@ -190,7 +190,7 @@ code-example(language="bash").
## 创建*AppComponent*
- The new `AppComponent` will be the application shell.
+ The new `AppComponent` will be the application shell.
It will have some navigation links at the top and a display area below for the pages we navigate to.
新的`AppComponent`将成为应用的“壳”。
@@ -259,7 +259,7 @@ code-example(language="bash").
我们可不希望在应用的两个不同层次上存在它的***两个副本***。
:marked
- The app still runs and still displays heroes.
+ The app still runs and still displays heroes.
Our refactoring of `AppComponent` into a new `AppComponent` and a `HeroesComponent` worked!
We have done no harm.
@@ -301,51 +301,27 @@ code-example(language="bash").
header base href是不可或缺的
:marked
- See the *base href* section of the [Router](../guide/router-deprecated.html#!#base-href) chapter to learn why this matters.
+ See the *base href* section of the [Router](../guide/router.html#!#base-href) chapter to learn why this matters.
查看[路由器](../guide/router-deprecated.html#!#base-href)一章的*base href*部分,了解为何如此。
:marked
- ### Make the router available.
-
- ### 让路由可用。
-
- The *Component Router* is a service. Like any service, we have to import it and make it
- available to the application by adding it to the `providers` array.
-
- *组件路由器*是一个服务。像所有服务一样,我们得导入它,并且把它加入`providers`数组来让它在应用中可用。
-
- The Angular router is a combination of multiple services (`ROUTER_PROVIDERS`), multiple directives (`ROUTER_DIRECTIVES`),
- and a configuration decorator (`RouteConfig`). We'll import them all together:
+ The Angular router is a combination of multiple provided services (`provideRouter`), multiple directives (`ROUTER_DIRECTIVES`),
+ and a configuration (`RouterConfig`). We'll configure our routes first:
Angular路由器是由多个服务(`ROUTER_PROVIDERS`)和多个指令(`ROUTER_DIRECTIVES`)以及一个配置装饰器(`RouteConfig`)组成的。我们一次性导入它们。
-
-+makeExample('toh-5/ts/app/app.component.2.ts', 'import-router', 'app/app.component.ts (router imports)')(format=".")
-:marked
- Next we update the `directives` and `providers` metadata arrays to *include* the router assets.
+ ### Configure and add the router
- 接下来,我们要更新`directives`和`providers`元数据数组,来包含这些路由器部件。
+ ### 配置与添加路由器
+
+ Our application doesn't have a router yet. We'll create a configuration file for our routes that
+ does two things
+ (a) configure that router with *routes*. (b) provide an export to add the router to our bootstrap
-+makeExample('toh-5/ts/app/app.component.2.ts', 'directives-and-providers', 'app/app.component.ts (directives and providers)')(format=".")
-:marked
- Notice that we also removed the `HeroesComponent` from the `directives` array.
- `AppComponent` no longer shows heroes; that will be the router's job.
- We'll soon remove `` from the template too.
-
- 注意,我们已经从`directives`数组中移除了`HeroesComponent`。`AppComponent`不会再显示英雄了,那是路由器的工作。
- 我们马上也会从模板中移除``。
-
- ### Add and configure the router
-
- ### 添加与配置路由器
-
- The `AppComponent` doesn't have a router yet. We'll use the `@RouteConfig` decorator to simultaneously
- (a) assign a router to the component and (b) configure that router with *routes*.
-
- `AppComponent`还没有路由器。我们使用`@RouteConfig`装饰器来同时 (a)为组件指定一个路由器,并 (b) 通过*路由*来配置路由器。
-
- *Routes* tell the router which views to display when a user clicks a link or
+ 我们的应用还没有路由器。我们得为这些路由创建一个配置文件,该文件要做两件事:(a) 使用*一些路由*配置路由器。(b) 提供一个导出,以便把该路由器添加到我们的启动代码。
+
+ *Routes* tell the router which views to display when a user clicks a link or
pastes a URL into the browser address bar.
*路由*告诉路由器,当用户点击链接或者把URL粘贴到浏览器地址栏时,应该显示哪个视图。
@@ -354,18 +330,20 @@ code-example(language="bash").
我们来定义第一个路由 —— 到`HeroesComponent`的路由。
-+makeExample('toh-5/ts/app/app.component.2.ts', 'route-config', 'app/app.component.ts (RouteConfig for heroes)')(format=".")
++makeExample('toh-5/ts/app/app.routes.2.ts', '', 'app/app.routes.ts')(format=".")
:marked
- `@RouteConfig` takes an array of *route definitions*.
- We have only one route definition at the moment but rest assured, we'll add more.
+ The `RouterConfig` is an array of *route definitions*.
+ We have only one route definition at the moment but rest assured, we'll add more.
- `@RouteConfig`有一个*路由定义*数组。
+
+ 这个`RouteConfig`是一个*路由定义*的数组。
此刻我们只有一个路由定义,但别急,后面还会添加更多。
This *route definition* has three parts:
“路由定义”包括三个部分:
+ This *route definition* has two parts:
* **path**: the router matches this route's path to the URL in the browser address bar (`/heroes`).
* **path**: 路由器会用它来匹配路由中指定的路径和浏览器地址栏中的当前路径,如`/heroes`。
@@ -380,16 +358,28 @@ code-example(language="bash").
.l-sub-section
:marked
- Learn more about defining routes with @RouteConfig in the [Routing](../guide/router-deprecated.html) chapter.
-
- 要学习更多使用`@RouteConfig`定义路由的知识,请参见[路由](../guide/router-deprecated.html)一章。
+ Learn more about defining routes with RouterConfig in the [Routing](../guide/router.html) chapter.
+ 要学习更多使用`RouterConfig`定义路由的知识,请参见[路由](../guide/router.html)一章。
+:marked
+ ### Make the router available.
+
+ ### 让路由器生效
+
+ The *Component Router* is a service. We have to import our `APP_ROUTER_PROVIDERS` which
+ contains our configured router and make it available to the application by adding it to
+ the `bootstrap` array.
+
+ *组件路由器*是一个服务。我们得导入`APP_ROUTER_PROVIDERS`(它包含了我们配置好的路由器),并通过把它添加到`bootstrap`的数组参数中让它在此应用中可用。
+
++makeExample('toh-5/ts/app/main.ts', '', 'app/main.ts')(format=".")
+
:marked
### Router Outlet
### 路由插座(Outlet)
- If we paste the path, `/heroes`, into the browser address bar,
+ If we paste the path, `/heroes`, into the browser address bar,
the router should match it to the `'Heroes'` route and display the `HeroesComponent`.
But where?
@@ -419,25 +409,25 @@ code-example(language="bash").
+makeExample('toh-5/ts/app/app.component.2.ts', 'template', 'app/app.component.ts (template v1)')(format=".")
:marked
- Notice the `[routerLink]` binding in the anchor tag.
+ Notice the `[routerLink]` binding in the anchor tag.
We bind the `RouterLink` directive (another of the `ROUTER_DIRECTIVES`) to an array
that tells the router where to navigate when the user clicks the link.
注意,a标签中的`[routerLink]`绑定。我们把`RouterLink`指令(`ROUTER_DIRECTIVES`中的另一个指令)绑定到一个数组。它将告诉路由器,当用户点击这个链接时,应该导航到哪里。
We define a *routing instruction* with a *link parameters array*.
- The array only has one element in our little sample, the quoted ***name* of the route** to follow.
- Looking back at the route configuration, we confirm that `'Heroes'` is the name of the route to the `HeroesComponent`.
+ The array only has one element in our little sample, the quoted ***path* of the route** to follow.
+ Looking back at the route configuration, we confirm that `'/heroes'` is the path of the route to the `HeroesComponent`.
我们通过一个*链接参数数组*定义了一个*路由说明*。
- 在这个小例子中,该数组只有一个元素,一个放在引号中的**路由名称**,作为路标。
- 回来看路由配置表,我们清楚的看到,这个名称 —— `'Heroes'`就是指向`HeroesComponent`的那个路由的名称。
+ 在这个小例子中,该数组只有一个元素,一个放在引号中的**路径**,作为路标。
+ 回来看路由配置表,我们清楚的看到,这个路径 —— `'/heroes'`就是指向`HeroesComponent`的那个路由的路径。
.l-sub-section
:marked
- Learn about the *link parameters array* in the [Routing](../guide/router-deprecated.html#link-parameters-array) chapter.
+ Learn about the *link parameters array* in the [Routing](../guide/router.html#link-parameters-array) chapter.
- 学习关于 *链接参数数组* 的更多知识,参见[路由](../guide/router-deprecated.html#link-parameters-array)一章。
+ 学习关于 *链接参数数组* 的更多知识,参见[路由](../guide/router.html#link-parameters-array)一章。
:marked
Refresh the browser. We see only the app title. We don't see the heroes list.
@@ -446,8 +436,8 @@ code-example(language="bash").
.l-sub-section
:marked
- The browser's address bar shows `/`.
- The route path to `HeroesComponent` is `/heroes`, not `/`.
+ The browser's address bar shows `/`.
+ The route path to `HeroesComponent` is `/heroes`, not `/`.
We don't have a route that matches the path `/`, so there is nothing to show.
That's something we'll want to fix.
@@ -456,7 +446,7 @@ code-example(language="bash").
接下来,我们就修复这个问题。
:marked
- We click the "Heroes" navigation link, the browser bar updates to `/heroes`,
+ We click the "Heroes" navigation link, the browser bar updates to `/heroes`,
and now we see the list of heroes. We are navigating at last!
我们点击“英雄列表(Heroes)”导航链接,浏览器地址栏更新为`/heroes`,并且看到了英雄列表。我们终于导航过去了!
@@ -497,36 +487,41 @@ code-example(language="bash").
### 配置仪表盘路由
- Go back to `app.component.ts` and teach it to navigate to the dashboard.
+ Go back to `app.routes.ts` and teach it to navigate to the dashboard.
- 回到`app.component.ts`文件,我们得教它如何导航到这个仪表盘。
+ 回到`app.routes.ts`文件,我们得教它如何导航到这个仪表盘。
Import the `DashboardComponent` so we can reference it in the dashboard route definition.
先导入`DashboardComponent`类,这样我们就可以在仪表盘的路由定义中引用它了。
- Add the following `'Dashboard'` route definition to the `@RouteConfig` array of definitions.
+ Add the following `'Dashboard'` route definition to the `RouterConfig` array of definitions.
然后把下列`'Dashboard'`路由的定义添加到`@RouteConfig`数组中。
-+makeExample('toh-5/ts/app/app.component.ts','dashboard-route', 'app/app.component.ts (Dashboard route)')(format=".")
++makeExample('toh-5/ts/app/app.routes.1.ts','dashboard-route', 'app/app.routes.ts (Dashboard route)')(format=".")
+
.l-sub-section
:marked
- **useAsDefault**
-
- We want the app to show the dashboard when it starts and
+ **Redirect**
+
+ We want the app to show the dashboard when it starts and
we want to see a nice URL in the browser address bar that says `/dashboard`.
Remember that the browser launches with `/` in the address bar.
- We don't have a route for that path and we'd rather not create one.
+ We can use a redirect route to make this happen.
我们希望在应用启动的时候就显示仪表盘,而且我们希望在浏览器的地址栏看到一个好看的URL,比如`/dashboard`。
- 记住,浏览器启动时,在地址栏中使用的路径是`/`。我们没有指向这个路径的路由,也不想单独创建它。
+ 记住,浏览器启动时,在地址栏中使用的路径是`/`。
+ 我们可以使用一个重定向路由来达到目的。
- Fortunately we can add the `useAsDefault: true` property to the *route definition* and the
- router will display the dashboard when the browser URL doesn't match an existing route.
++makeExample('toh-5/ts/app/app.routes.1.ts','redirect-route', 'app/app.routes.ts (Redirect route)')(format=".")
- 幸运的是,我们可以把`useAsDefault: true`属性添加到*路由定义*上。这样,如果浏览器中的URL匹配不上任何已知的路由,路由器就会显示这个仪表盘组件。
+.l-sub-section
+ :marked
+ Learn about the *redirects* in the [Routing](../guide/router.html#!#redirect) chapter.
+ 要学习关于*重定向*的更多知识,参见[路由与导航](../guide/router.html#!#redirect)一章。
+
:marked
Finally, add a dashboard navigation link to the template, just above the *Heroes* link.
@@ -535,14 +530,14 @@ code-example(language="bash").
+makeExample('toh-5/ts/app/app.component.ts','template', 'app/app.component.ts (template)')(format=".")
.l-sub-section
:marked
- We nestled the two links within `