diff --git a/public/docs/_includes/_help.jade b/public/docs/_includes/_help.jade index 7322e7dfcb..e69de29bb2 100644 --- a/public/docs/_includes/_help.jade +++ b/public/docs/_includes/_help.jade @@ -1,61 +0,0 @@ -.l-main-section - h2 Get Help Using Angular - h2 获得使用Angular的帮助 - - p. - We have an incredible community of developers who are passionate about solving problems. - We recommend some of the following methods to get help with Angular. - 我们有一个难以置信的开发者社区,他们充满激情的解决问题。我们建议您通过下列方式获取关于Angular的帮助: - - - .l-sub-section - h3 Angular Google Group - - ol - li. - Search the archive first. - It's likely that your question has already been answered. - li. - 先搜索文档。 - 你的问题很可能有别人问过了。 - li. - To avoid the spam moderation queue, - don't include code directly in your email. (See #3) - li. - 为了避免被当成垃圾邮件,请不要在你的邮件中包含代码。(参见下一条) - li. - Link to a live code example that demonstrates your problem or question, - so you'll get an answer faster. - Use this template. - li. - 给出一个“活代码范例”的链接,来演示你的难题或问题,那样你会更快的获得答案。 - 使用这个模板。 - li. - If you get help, help others. Good karma rulez! - li. - 如果得到了帮助,别忘了帮助别人。人生金律! - - a(href="https://groups.google.com/forum/#!forum/angular" class="button button-primary" md-button) View the Google Group - - a(href="https://groups.google.com/forum/#!forum/angular" class="button button-primary" md-button) 访问Google Group - - .l-sub-section - h3 Angular Chat Room - h3 Angular聊天室 - - p Talk in real time with other Angular developers. - p 和其他Angular开发者实时聊天。 - - a(href="http://webchat.freenode.net/?channels=angularjs&uio=d4" class="button button-primary" md-button) View the Chat Room - a(href="http://webchat.freenode.net/?channels=angularjs&uio=d4" class="button button-primary" md-button) 访问聊天室 - - - .l-sub-section - h3 Report an Issue - h3 报告问题 - - p If you run into an issue or have a feature request, you can create a new issue on our GitHub repository. - p 如果你遇到了问题或者需要某些特性,你可以在我们的Github仓库中创建一个新的issue。 - - a(href="https://github.com/angular/angular/issues" class="button button-primary" md-button) Report an Issue - a(href="https://github.com/angular/angular/issues" class="button button-primary" md-button) 报告问题 diff --git a/public/docs/_includes/styleguide/_alerts.jade b/public/docs/_includes/styleguide/_alerts.jade index 14684d3c8f..522ba11109 100644 --- a/public/docs/_includes/styleguide/_alerts.jade +++ b/public/docs/_includes/styleguide/_alerts.jade @@ -9,7 +9,7 @@ on top of each other. p. 请在文档中严谨的使用警告。这意味着只在重要的场合用它吸引注意力。 - 不要用警告表现多行内容(使用插图代替),也不要把它们堆叠在一起。 + 不要用警告表现多行内容(使用插图代替),也不要把它们堆叠在一起。 .showcase-content .l-sub-section h3 Adding an alert diff --git a/public/docs/js/latest/cookbook/ts-to-js.jade b/public/docs/js/latest/cookbook/ts-to-js.jade index ea89f0194f..93e3a9fb01 100644 --- a/public/docs/js/latest/cookbook/ts-to-js.jade +++ b/public/docs/js/latest/cookbook/ts-to-js.jade @@ -139,7 +139,7 @@ table(width="100%") These practices together prevent our code from polluting the global scope. - 我们经常在`window`对象上附加一个应用程序命名空间对象(比如`"app"`),然后把所要共享一切都附加到这个对象上。 + 我们经常在`window`对象上附加一个应用程序命名空间对象(比如`"app"`),然后把所要共享一切都附加到这个对象上。 也可以把我们的代码包装进一个[立即调用函数表达式IIFE](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression)。 这些实践可以防止我们的代码污染全局作用域。 @@ -210,7 +210,7 @@ table(width="100%") ES5 JavaScript has no classes. We use the constructor pattern instead which works with Angular 2 as well as classes do. - ES5 JavaScript不支持类,我们使用构造器模式(constructor pattern)来代替它,它可以和类一样与Angular 2协同工作。 + ES5 JavaScript不支持类,我们使用构造器模式(constructor pattern)来代替它,它可以和类一样与Angular 2协同工作。 +makeExample('cb-ts-to-js/js/app/hero.component.js', 'constructorproto')(format="." ) @@ -382,7 +382,7 @@ table(width="100%") There is no equivalent of a property decorator in ES5 JavaScript. Instead, we add comparable information to the `Component` (or `Directive`) metadata. - 在ES5 JavaScript里并没有属性装饰器的等价物,但我们可以往`Component`(或者`Directive`)的元数据中添加对应的信息。 + 在ES5 JavaScript里并没有属性装饰器的等价物,但我们可以往`Component`(或者`Directive`)的元数据中添加对应的信息。 In this example, we add `inputs` and `outputs` array attributes containing the input and output property names. 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 8826e82c16..1fed18690c 100644 --- a/public/docs/ts/latest/cookbook/a1-a2-quick-reference.jade +++ b/public/docs/ts/latest/cookbook/a1-a2-quick-reference.jade @@ -518,7 +518,7 @@ table(width="100%") and event binding (from the view to the component), thereby giving us two-way binding. 在Angular 2中,**双向绑定**使用[()]标记出来,它被形象的比作“盒子中的香蕉”。 - 这种语法是一个简写形式,用来同时定义一个属性绑定(从组件到视图)和一个事件绑定(从视图到组件),因此,我们得到了双向绑定。 + 这种语法是一个简写形式,用来同时定义一个属性绑定(从组件到视图)和一个事件绑定(从视图到组件),因此,我们得到了双向绑定。 For more information on two-way binding with ngModel see [Template Syntax](../guide/template-syntax.html#ngModel). @@ -551,7 +551,7 @@ table(width="100%") Angular 2中的`*ngFor`指令类似于Angular 1中的`ng-repeat`指令。 它为指定集合中的每一个条目重复渲染了相关的DOM元素。 - 更准确的说,它把被界定出来的元素(这个例子中是`tr`)及其内容转成了一个模板,并使用那个模板来为列表中的每一个条目实例化一个视图。 + 更准确的说,它把被界定出来的元素(这个例子中是`tr`)及其内容转成了一个模板,并使用那个模板来为列表中的每一个条目实例化一个视图。 Notice the other syntax differences: The (*) before `ngFor` is required; @@ -1000,7 +1000,7 @@ table(width="100%") In Angular 1, we often defined an immediately invoked function expression (or IIFE) around our controller code. This kept our controller code out of the global namespace. - 在Angular 1中,我们通常会定义一个立即调用的函数表达式(IIFE)来包裹我们的控制器代码。 + 在Angular 1中,我们通常会定义一个立即调用的函数表达式(IIFE)来包裹我们的控制器代码。 这样让控制器代码不会污染全局命名空间。 td diff --git a/public/docs/ts/latest/cookbook/component-communication.jade b/public/docs/ts/latest/cookbook/component-communication.jade index bc87de81f8..31e9bd8a94 100644 --- a/public/docs/ts/latest/cookbook/component-communication.jade +++ b/public/docs/ts/latest/cookbook/component-communication.jade @@ -66,7 +66,7 @@ include ../_util-fns :marked The second `@Input` aliases the child component property name `masterName` as `'master'`. - 第二个`@Input`为子组件的属性名`masterName`指定一个别名`master`(译者注:不推荐为起别名,请参见风格指南). + 第二个`@Input`为子组件的属性名`masterName`指定一个别名`master`(译者注:不推荐为起别名,请参见风格指南). The `HeroParentComponent` nests the child `HeroChildComponent` inside an `*ngFor` repeater, binding its `master` string property to the child's `master` alias and each iteration's `hero` instance to the child's `hero` property. @@ -203,7 +203,7 @@ figure.image-display The child component exposes an `EventEmitter` property with which it `emits`events when something happens. The parent binds to that event property and reacts to those events. - 子组件暴露一个`EventEmitter`属性,当事件发生时,子组件利用该属性`emits`(向上弹射)事件。父组件绑定到这个事件属性,并在事件发生时作出回应。 + 子组件暴露一个`EventEmitter`属性,当事件发生时,子组件利用该属性`emits`(向上弹射)事件。父组件绑定到这个事件属性,并在事件发生时作出回应。 The child's `EventEmitter` property is an ***output property***, typically adorned with an [@Output decoration](../guide/template-syntax.html#inputs-outputs) as seen in this `VoterComponent`: @@ -214,7 +214,7 @@ figure.image-display :marked Clicking a button triggers emission of a `true` or `false` (the boolean *payload*). - 点击按钮会触发`true`或`false`(布尔型*有效载荷*)的事件。 + 点击按钮会触发`true`或`false`(布尔型*有效载荷*)的事件。 The parent `VoteTakerComponent` binds an event handler (`onVoted`) that responds to the child event payload (`$event`) and updates a counter. @@ -225,7 +225,7 @@ figure.image-display :marked The framework passes the event argument — represented by `$event` — to the handler method, and the method processes it: - 框架(Angular)把事件参数(用`$event`表示)传给事件处理方法,这个方法会处理: + 框架(Angular)把事件参数(用`$event`表示)传给事件处理方法,这个方法会处理: figure.image-display img(src="/resources/images/cookbooks/component-communication/child-to-parent.gif" alt="Child-to-parent") @@ -407,7 +407,7 @@ a(id="countdown-tests") :marked The `MissionControlComponent` both provides the instance of the service that it shares with its children (through the `providers` metadata array) and injects that instance into itself through its constructor: - `MissionControlComponent`提供服务的实例,并将其共享给它的子组件(通过`providers`元数据数组),子组件可以通过构造函数将该实例注入到自身。 + `MissionControlComponent`提供服务的实例,并将其共享给它的子组件(通过`providers`元数据数组),子组件可以通过构造函数将该实例注入到自身。 +makeExample('cb-component-communication/ts/app/missioncontrol.component.ts') diff --git a/public/docs/ts/latest/cookbook/component-relative-paths.jade b/public/docs/ts/latest/cookbook/component-relative-paths.jade index 3681aeee0f..2dd3df9fdc 100644 --- a/public/docs/ts/latest/cookbook/component-relative-paths.jade +++ b/public/docs/ts/latest/cookbook/component-relative-paths.jade @@ -47,7 +47,7 @@ include ../_util-fns with a suitable package loader such as `systemjs` or `webpack`. Learn why [below](#why-default). - 如果把应用构建成`commonjs`模块,并用一个合适的包加载器(比如`systemjs`或`webpack`)加载那些模块,我们就可以用相对路径。 + 如果把应用构建成`commonjs`模块,并用一个合适的包加载器(比如`systemjs`或`webpack`)加载那些模块,我们就可以用相对路径。 [在下方](#why-default)可以学到原理。 The Angular 2 CLI uses these technologies and defaults to the diff --git a/public/docs/ts/latest/cookbook/dependency-injection.jade b/public/docs/ts/latest/cookbook/dependency-injection.jade index 8da5d19fbf..5b9367665e 100644 --- a/public/docs/ts/latest/cookbook/dependency-injection.jade +++ b/public/docs/ts/latest/cookbook/dependency-injection.jade @@ -134,7 +134,7 @@ include ../_util-fns (the `LoggerService`, `UserContext`, and the `UserService`) in the `@Component` metadata `providers` array. - 在下面的例子中,通过`@Component`元数据的`providers`数组导入和注册了几个服务(`LoggerService`, `UserContext`和`UserService`)。 + 在下面的例子中,通过`@Component`元数据的`providers`数组导入和注册了几个服务(`LoggerService`, `UserContext`和`UserService`)。 +makeExample('cb-dependency-injection/ts/app/app.component.ts','import-services','app/app.component.ts (excerpt)')(format='.') :marked @@ -176,7 +176,7 @@ include ../_util-fns but (a) aren't conceptually part of the application and (b) that we could change later without altering the essential logic of the application. - 使用外部模块时,如果满足下面两个条件,就应该在引导过程中注册:a)它在概念上不是我们程序的一部分,以及 b)将来我们可能要在不改变主要应用逻辑的情况下更换它。 + 使用外部模块时,如果满足下面两个条件,就应该在引导过程中注册:a)它在概念上不是我们程序的一部分,以及 b)将来我们可能要在不改变主要应用逻辑的情况下更换它。 For example, we might configure the Component Router with different [location strategies](../guide/router.html#location-strategy) based on environmental factors. @@ -189,7 +189,7 @@ include ../_util-fns We'll switch to the real backend in production. The application shouldn't know or care one way or the other. - 在开发过程中,可以偷偷把一个假的带样本数据的HTTP后端嵌入进来,以代替对一个远程服务器(可能还不存在)进行http查询。我们在产品发布时再切换到真正的后端。应用程序不用知道也不用管正在跟哪个后端打交道。 + 在开发过程中,可以偷偷把一个假的带样本数据的HTTP后端嵌入进来,以代替对一个远程服务器(可能还不存在)进行http查询。我们在产品发布时再切换到真正的后端。应用程序不用知道也不用管正在跟哪个后端打交道。 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. @@ -229,7 +229,7 @@ a(id="nested-dependencies") The `UserContext` in turn has dependencies on both the `LoggerService` (again) and a `UserService` that gathers information about a particular user. - `UserContext`有两个依赖`LoggerService`(再一次)和负责获取特定用户信息的`UserService`。 + `UserContext`有两个依赖`LoggerService`(再一次)和负责获取特定用户信息的`UserService`。 +makeExample('cb-dependency-injection/ts/app/user-context.service.ts','injectables','user-context.service.ts (injection)')(format='.') @@ -314,7 +314,7 @@ figure.image-display So a particular service can be *provided* (and created) at any component level and multiple times if provided in multiple components. - 但是Angular应用程序有多个依赖注入器,组织成一个与组件树平行的树状结构。所以,可以在任何组件级别*提供*(和建立)特定的服务。如果在多个组件中注入,服务就会被新建出多个实例,分别提供给不同的组件。 + 但是Angular应用程序有多个依赖注入器,组织成一个与组件树平行的树状结构。所以,可以在任何组件级别*提供*(和建立)特定的服务。如果在多个组件中注入,服务就会被新建出多个实例,分别提供给不同的组件。 By default, a service dependency provided in one component is visible to all of its child components and Angular injects the same service instance into all child components that ask for that service. @@ -342,7 +342,7 @@ figure.image-display When Angular creates the `HeroesBaseComponent`, it also creates a new instance of `HeroService` that is visible only to the component and its children (if any). - 当Angular新建`HeroBaseComponent`的时候,它会同时新建一个`HeroService`实例,该实例只在该组件及其子组件(如果有)中可见。 + 当Angular新建`HeroBaseComponent`的时候,它会同时新建一个`HeroService`实例,该实例只在该组件及其子组件(如果有)中可见。 We could also provide the `HeroService` to a *different* component elsewhere in the application. That would result in a *different* instance of the service, living in a *different* injector. @@ -374,7 +374,7 @@ figure.image-display .l-main-section :marked ## Multiple service instances (sandboxing) - ## 多个服务实例(sandboxing) + ## 多个服务实例(sandboxing) Sometimes we want multiple instances of a service at *the same level of the component hierarchy*. @@ -411,7 +411,7 @@ figure.image-display Each `HeroBioComponent` gets its *own* `HeroCacheService` instance by listing the `HeroCacheService` in its metadata `providers` array. - 通过在自己的元数据(metadata)`providers`数组里面列出`HeroCacheService`, 每个`HeroBioComponent`就能*拥有*自己独立的`HeroCacheService`实例。 + 通过在自己的元数据(metadata)`providers`数组里面列出`HeroCacheService`, 每个`HeroBioComponent`就能*拥有*自己独立的`HeroCacheService`实例。 +makeExample('cb-dependency-injection/ts/app/hero-bio.component.ts','component','app/hero-bio.component.ts') :marked @@ -453,13 +453,13 @@ a(id="qualify-dependency-lookup") used individually or together. 大部分时候,我们确实*想要*这个行为。 - 但是有时候,我们需要限制这个(依赖)查找逻辑,且/或提供一个缺失的依赖。 + 但是有时候,我们需要限制这个(依赖)查找逻辑,且/或提供一个缺失的依赖。 单独或联合使用`@Host`和`@Optional`限定型装饰器,我们就可以修改Angular的查找行为。 The `@Optional` decorator tells Angular to continue when it can't find the dependency. Angular sets the injection parameter to `null` instead. - 当Angular找不到依赖时,`@Optional`装饰器会告诉Angular继续执行。Angular把此注入参数设置为`null`(而不用默认的抛出错误的行为)。 + 当Angular找不到依赖时,`@Optional`装饰器会告诉Angular继续执行。Angular把此注入参数设置为`null`(而不用默认的抛出错误的行为)。 The `@Host` decorator stops the upward search at the *host component*. @@ -490,7 +490,7 @@ a(id="qualify-dependency-lookup") Angular *projects* (*transcludes*) the corresponding `HeroContactComponent` into the `HeroBioComponent` view, placing it in the `` slot of the `HeroBioComponent` template: - 我们在``标签中插入了``元素。Angular就会把相应的`HeroContactComponent`*投影*(*transclude*)进`HeroBioComponent`的视图里, + 我们在``标签中插入了``元素。Angular就会把相应的`HeroContactComponent`*投影*(*transclude*)进`HeroBioComponent`的视图里, 将它放在`HeroBioComponent`模板的``标签槽里。 +makeExample('cb-dependency-injection/ts/app/hero-bio.component.ts','template','app/hero-bio.component.ts (template)')(format='.') @@ -504,7 +504,7 @@ figure.image-display :marked Here's the `HeroContactComponent` which demonstrates the qualifying decorators that we're talking about in this section: - 下面的`HeroContactComponent`,示范了我们在本节一直在讨论的限定型装饰器(@Optional和@Host): + 下面的`HeroContactComponent`,示范了我们在本节一直在讨论的限定型装饰器(@Optional和@Host): +makeExample('cb-dependency-injection/ts/app/hero-contact.component.ts','component','app/hero-contact.component.ts') :marked @@ -573,7 +573,7 @@ figure.image-display Although we strive to avoid it, many visual effects and 3rd party tools (such as jQuery) require DOM access. - 偶尔,我们可能需要访问一个组件对应的DOM元素。我们尽量避免这样做,但还是有很多视觉效果和第三方工具(比如jQuery)需要访问DOM。 + 偶尔,我们可能需要访问一个组件对应的DOM元素。我们尽量避免这样做,但还是有很多视觉效果和第三方工具(比如jQuery)需要访问DOM。 To illustrate, we've written a simplified version of the `HighlightDirective` from the [Attribute Directives](../guide/attribute-directives.html) chapter. @@ -722,7 +722,7 @@ a(id='provide') The *definition* object has one main property, (e.g. `useValue`) that indicates how the provider should create or return the provided value. - 该*定义*对象有一个主属性(即`userValue`),用来标识该供应商会如何新建和返回依赖。 + 该*定义*对象有一个主属性(即`userValue`),用来标识该供应商会如何新建和返回依赖。 .l-main-section a(id='usevalue') @@ -739,7 +739,7 @@ a(id='usevalue') We often use a *value provider* in a unit test to replace a production service with a fake or mock. 使用该技巧来进行*运行期常量设置*,比如网站的基础地址和功能标志等。 - 我们通常在单元测试中使用*值-供应商*,用一个假的或模仿的(服务)来取代一个生产环境的服务。 + 我们通常在单元测试中使用*值-供应商*,用一个假的或模仿的(服务)来取代一个生产环境的服务。 The `HeroOfTheMonthComponent` example has two *value providers*. The first provides an instance of the `Hero` class; @@ -938,7 +938,7 @@ a(id="tokens") Angular dependency injection is easiest when the provider *token* is a class that is also the type of the returned dependency object (what we usually call the *service*). - Angular依赖注入当*令牌*是类的时候是最简单的,该类同时也是返回的依赖对象的类型(我们通常直接称之为*服务*)。 + Angular依赖注入当*令牌*是类的时候是最简单的,该类同时也是返回的依赖对象的类型(我们通常直接称之为*服务*)。 But the token doesn't have to be a class and even when it is a class, it doesn't have to be the same type as the returned object. @@ -977,7 +977,7 @@ a(id="tokens") `DateLoggerService` inherits (extends) from `LoggerService`, not `MinimalLogger`. The `DateLoggerService` *implements* `MinimalLogger` as if `MinimalLogger` were an *interface*. - `DateLoggerService`继承(扩展)了`LoggerService`,而不是`MinimalLogger`。该`DateLoggerService`*实现了*`MinimalLogger`,就像`MinimalLogger`是一个接口一样。 + `DateLoggerService`继承(扩展)了`LoggerService`,而不是`MinimalLogger`。该`DateLoggerService`*实现了*`MinimalLogger`,就像`MinimalLogger`是一个接口一样。 We call a class used in this way a ***class-interface***. The key benefit of a *class-interface* is that we can get the strong-typing of an interface @@ -1094,7 +1094,7 @@ figure.image-display This rule makes the component safe to construct under test without fear that it will do something dramatic like talk to the server. That's why we call the `HeroService` from within the `ngOnInit` rather than the constructor. - 我们强烈推荐简单的构造函数。它们应该***只***用来初始化变量。这个规则会帮助我们在测试环境中放心的构造组件,以免在构造它们时,无意做了一些非常戏剧化的动作(比如连接服务)。 + 我们强烈推荐简单的构造函数。它们应该***只***用来初始化变量。这个规则会帮助我们在测试环境中放心的构造组件,以免在构造它们时,无意做了一些非常戏剧化的动作(比如连接服务)。 这就是为什么我们要在`ngOnInit`里面调用`HeroService`,而不是在构造函数中。 We explain the mysterious `afterGetHeroes` below. @@ -1109,7 +1109,7 @@ figure.image-display (we said it was contrived). 用户希望看到英雄按字母顺序排序。与其修改原始的组件,不如派生它,新建`SortedHeroesComponent`,以便展示英雄之前进行排序。 - `SortedHeroesComponent`让基类来获取英雄。(我们说过这是生造的,仅用来解释这种机制)。 + `SortedHeroesComponent`让基类来获取英雄。(我们说过这是生造的,仅用来解释这种机制)。 Unfortunately, Angular cannot inject the `HeroService` directly into the base class. We must provide the `HeroService` again for *this* component, @@ -1160,7 +1160,7 @@ a(id="find-parent") There is an API for acquiring a child reference (checkout `Query`, `QueryList`, `ViewChildren`, and `ContentChildren`). - 有一个API可以获取子级的引用(请看`Query`, `QueryList`, `ViewChildren`,和`ContentChildren`)。 + 有一个API可以获取子级的引用(请看`Query`, `QueryList`, `ViewChildren`,和`ContentChildren`)。 There is no public API for acquiring a parent reference. But because every component instance is added to an injector's container, @@ -1216,7 +1216,7 @@ a(id='alex') For sound (cough) business reasons, this news component makes frequent calls directly into its parent instrument as changing market data stream by. - 一个可复用的组件可能是多个组件的子级。想象一个用来渲染金融工具头条新闻的组件。为了合理(咳咳)的商业理由,该新闻组件在实时变化的市场数据流过时,要频繁的直接调用其父级工具。 + 一个可复用的组件可能是多个组件的子级。想象一个用来渲染金融工具头条新闻的组件。为了合理(咳咳)的商业理由,该新闻组件在实时变化的市场数据流过时,要频繁的直接调用其父级工具。 The app probably defines more than a dozen financial instrument components. If we're lucky, they all implement the same base class @@ -1241,7 +1241,7 @@ a(id='alex') The sample's `CraigComponent` explores this question. [Looking back](#alex) we see that the `Alex` component *extends* (*inherits*) from a class named `Base`. - `CraigComponent`例子探究了这个问题。[往回看Alex]{#alex},我们看到`Alex`组件*扩展*(*派生*)自一个叫`Base`的类。 + `CraigComponent`例子探究了这个问题。[往回看Alex]{#alex},我们看到`Alex`组件*扩展*(*派生*)自一个叫`Base`的类。 +makeExample('cb-dependency-injection/ts/app/parent-finder.component.ts','alex-class-signature','parent-finder.component.ts (Alex class signature)')(format='.') :marked @@ -1331,7 +1331,7 @@ a(id="parent-tree") *Barry*'s `providers` array looks just like [*Alex*'s](#alex-providers). If we're going to keep writing [*alias providers*](#useexisting) like this we should create a [helper function](#provideparent). - *Barry*的`providers`数组看起来很像[*Alex*的那个](#alex-providers). + *Barry*的`providers`数组看起来很像[*Alex*的那个](#alex-providers). 如果我们准备一直像这样编写[*别名供应商*](#useexisting)的话,我们应该建立一个[帮助函数](#provideparent)。 For now, focus on *Barry*'s constructor: diff --git a/public/docs/ts/latest/cookbook/set-document-title.jade b/public/docs/ts/latest/cookbook/set-document-title.jade index 60cb1f28f0..a6e3c3eef1 100644 --- a/public/docs/ts/latest/cookbook/set-document-title.jade +++ b/public/docs/ts/latest/cookbook/set-document-title.jade @@ -48,7 +48,7 @@ code-example(format='') inside a Web Worker to improve your app's responsiveness by using multiple threads. And it means that you could run your app inside Electron.js or Windows Universal to deliver it to the desktop. - 在浏览器外运行应用程序意味着:利用服务器端预先渲染,为应用程序实现几乎实时的首次渲染,同时还能支持SEO(搜索引擎优化)。 + 在浏览器外运行应用程序意味着:利用服务器端预先渲染,为应用程序实现几乎实时的首次渲染,同时还能支持SEO(搜索引擎优化)。 意味着你可以在一个Web Worker中运行你的应用程序,通过多线程技术增强应用程序的响应性。 还意味着你可以在Electron.js或者Windows Universal里面运行,发布到桌面环境。 @@ -103,7 +103,7 @@ figure.image-display :marked Here's the complete solution - 这里是完整的方案(代码)。 + 这里是完整的方案(代码)。 +makeTabs( `cb-set-document-title/ts/app/main.ts, diff --git a/public/docs/ts/latest/glossary.jade b/public/docs/ts/latest/glossary.jade index c2b0322d5e..2d6deb3196 100644 --- a/public/docs/ts/latest/glossary.jade +++ b/public/docs/ts/latest/glossary.jade @@ -28,17 +28,17 @@ include _util-fns .l-main-section :marked ## Annotation - ## 注解(Annotation) + ## 注解(Annotation) .l-sub-section :marked In practice a synonym for [Decoration](#decorator). - [装饰器(Decoration)](#decorator)在实践中的同义词。 + [装饰器(Decoration)](#decorator)在实践中的同义词。 // #enddocregion a-1 // #docregion a-2 :marked ## Attribute Directive - ## 属性型指令(Attribute Directive) + ## 属性型指令(Attribute Directive) .l-sub-section :marked A category of [Directive](#directive) that can listen to and modify the behavior of @@ -61,7 +61,7 @@ include _util-fns .l-main-section :marked ## Barrel - ## 封装桶(Barrel) + ## 封装桶(Barrel) .l-sub-section :marked A barrel is a way to *rollup exports* from several modules into a single convenience module. @@ -93,7 +93,7 @@ include _util-fns :marked We can add a barrel to the `heroes` folder (called `index` by convention) that exports all of these items: - 我们可以在`heroes`目录下添加一个封装桶(按规约叫做`index`),它导出所有这三条: + 我们可以在`heroes`目录下添加一个封装桶(按规约叫做`index`),它导出所有这三条: code-example(format=''). export * from './hero.model.ts'; // re-export all of its exports export * from './hero.service.ts'; // re-export all of its exports @@ -169,8 +169,8 @@ include _util-fns This form is also known as **lower camel case**, to distinguish it from **upper camel case** which we call [PascalCase](#pascalcase). When we write "camelCase" in this documentation we always mean *lower camel case*. - 这种形式也被叫做**小驼峰式命名法(lower camel case)**,以区分于**大驼峰式命名法**(我们也叫[Pascal命名法(PascalCase)](#pascalcase))。 - 当我们在文档中提到“驼峰式命名法(camelCase)”的时候,所指的都是小驼峰命名法。 + 这种形式也被叫做**小驼峰式命名法(lower camel case)**,以区分于**大驼峰式命名法**(我们也叫[Pascal命名法(PascalCase)](#pascalcase))。 + 当我们在文档中提到“驼峰式命名法(camelCase)”的时候,所指的都是小驼峰命名法。 :marked ## Component @@ -231,7 +231,7 @@ include _util-fns Applications display data values to a user and respond to user actions (clicks, touches, keystrokes). - 应用程序会将数据展示给用户,并对用户的操作(点击、触屏、按键)做出回应。 + 应用程序会将数据展示给用户,并对用户的操作(点击、触屏、按键)做出回应。 We could push application data values into HTML, attach event listeners, pull changed values from the screen, and @@ -254,19 +254,19 @@ include _util-fns The many forms of binding include: 绑定形式包括: * [Interpolation](/docs/ts/latest/guide/template-syntax.html#interpolation) - * [插值表达式(Interpolation)](/docs/ts/latest/guide/template-syntax.html#interpolation) + * [插值表达式(Interpolation)](/docs/ts/latest/guide/template-syntax.html#interpolation) * [Property Binding](/docs/ts/latest/guide/template-syntax.html#property-binding) - * [属性绑定(Property Binding)](/docs/ts/latest/guide/template-syntax.html#property-binding) + * [属性绑定(Property Binding)](/docs/ts/latest/guide/template-syntax.html#property-binding) * [Event Binding](/docs/ts/latest/guide/template-syntax.html#event-binding) - * [事件绑定(Event Binding)](/docs/ts/latest/guide/template-syntax.html#event-binding) + * [事件绑定(Event Binding)](/docs/ts/latest/guide/template-syntax.html#event-binding) * [Attribute Binding](/docs/ts/latest/guide/template-syntax.html#attribute-binding) - * [Attribute绑定(Attribute Binding)](/docs/ts/latest/guide/template-syntax.html#attribute-binding) + * [Attribute绑定(Attribute Binding)](/docs/ts/latest/guide/template-syntax.html#attribute-binding) * [Class Binding](/docs/ts/latest/guide/template-syntax.html#class-binding) - * [CSS类绑定(Class Binding)](/docs/ts/latest/guide/template-syntax.html#class-binding) + * [CSS类绑定(Class Binding)](/docs/ts/latest/guide/template-syntax.html#class-binding) * [Style Binding](/docs/ts/latest/guide/template-syntax.html#style-binding) - * [样式绑定(Style Binding)](/docs/ts/latest/guide/template-syntax.html#style-binding) + * [样式绑定(Style Binding)](/docs/ts/latest/guide/template-syntax.html#style-binding) * [Two-way data binding with ngModel](/docs/ts/latest/guide/template-syntax.html#ng-model) - * [基于ngModel的双向数据绑定(Two-way data binding with ngModel)](/docs/ts/latest/guide/template-syntax.html#ng-model) + * [基于ngModel的双向数据绑定(Two-way data binding with ngModel)](/docs/ts/latest/guide/template-syntax.html#ng-model) Learn more about data binding in the [Template Syntax](/docs/ts/latest/guide/template-syntax.html#data-binding) chapter. @@ -282,11 +282,11 @@ include _util-fns :marked A Decorator is a **function** that adds metadata to a class, its members (properties, methods) and function arguments. - 装饰器是一个**函数**,这个函数将元数据添加到类、类成员(属性、方法)和函数上。 + 装饰器是一个**函数**,这个函数将元数据添加到类、类成员(属性、方法)和函数上。 Decorators are a JavaScript language [feature](https://github.com/wycats/javascript-decorators), implemented in TypeScript and proposed for ES2016 (AKA ES7). - 装饰器是一个JavaScript的语言[特性](https://github.com/wycats/javascript-decorators),装饰器在TypeScript里面已经采纳并实现了,并被推荐到了ES2016(也就是ES7)。 + 装饰器是一个JavaScript的语言[特性](https://github.com/wycats/javascript-decorators),装饰器在TypeScript里面已经采纳并实现了,并被推荐到了ES2016(也就是ES7)。 We apply a decorator by positioning it immediately above or to the left of the thing it decorates. @@ -435,7 +435,7 @@ include _util-fns as if they were writing native HTML. In this way, directives become extensions of HTML itself. - 开发人员可以为自定义指令指定自定义的HTML标签(比如``),然后,他们就可以像写原生HTML一样把这些自定义标签放到HTML模板里了。 + 开发人员可以为自定义指令指定自定义的HTML标签(比如``),然后,他们就可以像写原生HTML一样把这些自定义标签放到HTML模板里了。 这样,指令就变成了HTML本身的拓展。 Directives fall into one of three categories: @@ -478,13 +478,13 @@ include _util-fns either in this version of the language or a dialect that strives to be compatible with it such as [TypeScript](#typesScript). - 最新的被认可的JavaScript版本是[ECMAScript 2015](http://www.ecma-international.org/ecma-262/6.0/),(也叫“ES2015”或“ES6”)。Angular 2的开发者要么使用这个版本的JavaScript,要么使用与这个版本兼容的语言,比如[TypeScript](#typesScript)。 + 最新的被认可的JavaScript版本是[ECMAScript 2015](http://www.ecma-international.org/ecma-262/6.0/),(也叫“ES2015”或“ES6”)。Angular 2的开发者要么使用这个版本的JavaScript,要么使用与这个版本兼容的语言,比如[TypeScript](#typesScript)。 Most modern browsers today only support the prior "ECMAScript 5" (AKA ES5) standard. Applications written in ES2015 or one of its dialects must be "[transpiled](#transpile)" to ES5 JavaScript. - 目前,几乎所有现代游览器都只支持上一个版本的“ECMAScript 5” (也就是ES5)标准。使用ES2015或者其它兼容语言开发的应用程序,都必须被“[转译(Transpile)](#transpile)”成ES5 JavaScript。 + 目前,几乎所有现代游览器都只支持上一个版本的“ECMAScript 5” (也就是ES5)标准。使用ES2015或者其它兼容语言开发的应用程序,都必须被“[转译(Transpile)](#transpile)”成ES5 JavaScript。 Angular 2 developers may choose to write in ES5 directly. @@ -589,7 +589,7 @@ include _util-fns :marked The practice of writing compound words or phrases such that each word is separated by a dash or hyphen (-). - 使用中线(-)分隔每个单词来书写复合词或短语的命名方法。 + 使用中线(-)分隔每个单词来书写复合词或短语的命名方法。 Directive selectors and the root of filenames are often spelled in kebab-case. Examples include: `my-app` and the `hero-list.component.ts`. @@ -724,7 +724,7 @@ include _util-fns in the template expression to the right of the equal sign. 输出属性是指令的一种属性,它可作为[事件绑定](/docs/ts/latest/guide/template-syntax.html#property-binding)的 **目标** 。 - 事件流可以通过这个属性,流出到接收者(模板表达式等号的右边就是接收者)。 + 事件流可以通过这个属性,流出到接收者(模板表达式等号的右边就是接收者)。 See the [Template Syntax](/docs/ts/latest/guide/template-syntax.html#inputs-outputs) chapter. @@ -781,7 +781,7 @@ include _util-fns A Provider creates a new instance of a dependency for the Dependency Injection system. It relates a lookup token to code - sometimes called a "recipe" - that can create a dependency value. - 依赖注入系统依靠供应商来创建依赖的实例。它把一个供查阅用的令牌和代码(有时也叫“配方”)关联到一起,以便创建依赖值。 + 依赖注入系统依靠供应商来创建依赖的实例。它把一个供查阅用的令牌和代码(有时也叫“配方”)关联到一起,以便创建依赖值。 For example, `new Provider(Foo, {useClass: Foo})` creates a `Provider` that relates the `Foo` token to a function that creates a new instance of the `Foo` class. @@ -920,7 +920,7 @@ include _util-fns The process of transforming code written in one form of JavaScript (e.g., TypeScript) into another form of JavaScript (e.g., [ES5](#es5)). - 把用JavaScript的某种形态(比如TypeScript)编写的程序转换成另一个形式的JavaScript(例如[ES5](#es5))的过程。 + 把用JavaScript的某种形态(比如TypeScript)编写的程序转换成另一个形式的JavaScript(例如[ES5](#es5))的过程。 :marked ## TypeScript .l-sub-section @@ -929,14 +929,14 @@ include _util-fns language features and many features that may arrive in future versions of JavaScript such as [Decorators](#decorator). - 一种支持了几乎所有[ECMAScript 2015](#ecmascript=2015)语言特性和一些未来版本可能有的特性(比如[装饰器(Decorator)](#decorator))的JavaScript语言。 + 一种支持了几乎所有[ECMAScript 2015](#ecmascript=2015)语言特性和一些未来版本可能有的特性(比如[装饰器(Decorator)](#decorator))的JavaScript语言。 TypeScript is also noteable for its optional typing system which gives us compile-time type-checking and strong tooling support (e.g. "intellisense", code completion, refactoring, and intelligent search). Many code editors and IDEs support TypeScript either natively or with plugins. - TypeScript同时也以它的可选类型系统著称。该类型系统给我们提供了编译期类型检查和强大的工具支持(比如“Intellisense”, 自动代码补齐,重构和智能搜索等)。许多程序编辑器和开发环境都自带了TypeScript支持或通过插件提供支持。 + TypeScript同时也以它的可选类型系统著称。该类型系统给我们提供了编译期类型检查和强大的工具支持(比如“Intellisense”, 自动代码补齐,重构和智能搜索等)。许多程序编辑器和开发环境都自带了TypeScript支持或通过插件提供支持。 TypeScript is the preferred language for Angular 2 development although we are welcome to write in other JavaScript dialects such as [ES5](#es5). @@ -1002,7 +1002,7 @@ include _util-fns [XHR](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) calls to remote servers. - 浏览器中的DOM和JavaScript之间常会有一些数量有限的异步活动,比如DOM事件(如点击)、[承诺(Promise)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ + 浏览器中的DOM和JavaScript之间常会有一些数量有限的异步活动,比如DOM事件(如点击)、[承诺(Promise)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ Promise)、和通过[XHR](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest)查询远程服务等。 Zones intercept all of these activities and give a "zone client" the opportunity diff --git a/public/docs/ts/latest/guide/_data.json b/public/docs/ts/latest/guide/_data.json index 39f69b1ca6..a9e6d91af6 100644 --- a/public/docs/ts/latest/guide/_data.json +++ b/public/docs/ts/latest/guide/_data.json @@ -38,7 +38,7 @@ "dependency-injection": { "title": "依赖注入", - "intro": "Angular的依赖注入系统能够JIT(刚好及时)的创建和交付所依赖的服务。", + "intro": "Angular的依赖注入系统能够JIT(刚好及时)的创建和交付所依赖的服务。", "nextable": true, "basics": true }, diff --git a/public/docs/ts/latest/guide/architecture.jade b/public/docs/ts/latest/guide/architecture.jade index 1e8f9a38e5..82bc4aaf39 100644 --- a/public/docs/ts/latest/guide/architecture.jade +++ b/public/docs/ts/latest/guide/architecture.jade @@ -112,12 +112,12 @@ figure Each chapter has plenty to offer after you steer clear of the `import` and `export` statements. Angular本身并不需要模块化方案,也不需要使用这种特定的语法。如果你不喜欢,可以不用它。 - 就算你避开`import`和`export`语句,每章也会为你提供很多(知识)。 + 就算你避开`import`和`export`语句,每章也会为你提供很多(知识)。 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. - 在JavaScript(你可以从页面顶部的组合框选择JavaScript)分支下,可以找到如何安装和组织的线索。 + 在JavaScript(你可以从页面顶部的组合框选择JavaScript)分支下,可以找到如何安装和组织的线索。 它示范了如何用老版本的JavaScript语言,在没有模块化系统支持的情况下进行Angular 2应用程序的开发。 :marked Perhaps the first module we meet is a module that exports a *component* class. @@ -153,7 +153,7 @@ figure The **module name** (AKA module id) is often the same as the filename without its extension. `import`语句告诉系统,它能从附近名叫`app.component`的文件中获得`AppComponent`组件。 - **模块名**(又叫模块ID)通常和去掉扩展名后的文件名相同。 + **模块名**(又叫模块ID)通常和去掉扩展名后的文件名相同。 ### Library Modules ### 模块库 @@ -171,7 +171,7 @@ figure Angular本身就是通过npm包发布的一组模块库,它们都以`@angular`为前缀。 每个Angular库中都包含一个[封装桶](../glossary.html#barrel)模块。 - 它实际上是一个公开的外观层(façade),囊括了一些逻辑相关的私有模块。 + 它实际上是一个公开的外观层(façade),囊括了一些逻辑相关的私有模块。 The `@angular/core` library is the primary Angular library module from which we get most of what we need. @@ -208,8 +208,8 @@ figure We could path up and around the application folder structure if the source module were somewhere else. 当我们从*自己的*文件中导入时,模块名中带有路径前缀。 - 在这个例子中,前缀是一个相对路径(./)。这表示源模块和想导入它的模块位于同一个目录中(./)。 - 如果源模块位于其它位置,我们还可以向上引用应用目录结构中的任意路径(如`../../../somewhere/`)。 + 在这个例子中,前缀是一个相对路径(./)。这表示源模块和想导入它的模块位于同一个目录中(./)。 + 如果源模块位于其它位置,我们还可以向上引用应用目录结构中的任意路径(如`../../../somewhere/`)。 .l-sub-section :marked We import and export in the ECMAScript 2015 (ES2015) module syntax. @@ -266,7 +266,7 @@ figure We define a Component's application logic - what it does to support the view - inside a class. The class interacts with the view through an API of properties and methods. - 我们在类中定义组件的应用逻辑(它被用来为视图提供支持)。 + 我们在类中定义组件的应用逻辑(它被用来为视图提供支持)。 组件通过一些由属性和方法组成的API与视图交互。 @@ -313,7 +313,7 @@ figure We define a Component's view with its companion **template**. A template is a form of HTML that tells Angular how to render the Component. - 我们通过组件的自带的**模板**来定义视图。模板以HTML形式存在,用来告诉Angular如何渲染组件(视图)。 + 我们通过组件的自带的**模板**来定义视图。模板以HTML形式存在,用来告诉Angular如何渲染组件(视图)。 A template looks like regular HTML much of the time ... and then it gets a bit strange. Here is a template for our `HeroList` component. @@ -350,7 +350,7 @@ figure The `HeroDetailComponent` is a **child** of the `HeroListComponent`. `HeroDetailComponent`跟我们以前回顾过的`HeroListComponent`是*不同*的组件。 - `HeroDetailComponent`(未展示代码)用于展现一个特定英雄的情况,这个英雄是用户从`HeroListComponent`列表中选择的。 + `HeroDetailComponent`(未展示代码)用于展现一个特定英雄的情况,这个英雄是用户从`HeroListComponent`列表中选择的。 `HeroDetailComponent`是`HeroListComponent`的*子组件*。 figure @@ -406,7 +406,7 @@ figure Here we see the `@Component` decorator which (no surprise) identifies the class immediately below it as a Component class. - 这里我们看到`@Component`装饰器(毫无悬念的)把紧随其后的类标记成了组件类。 + 这里我们看到`@Component`装饰器(毫无悬念的)把紧随其后的类标记成了组件类。 A decorator is a function. Decorators often have a configuration parameter. The `@Component` decorator takes a required configuration object with the @@ -424,7 +424,7 @@ figure If the template of the application shell (a Component) contained * `selector` - 一个css选择器,它告诉Angular在*父级*HTML中寻找一个``标签,然后创建该组件,并插入此标签中。 - 比如,如果应用“壳”(组件)的模板包含如下代码: + 比如,如果应用“壳”(组件)的模板包含如下代码:
code-example(language="html"). @@ -612,12 +612,12 @@ figure :marked There are two *other* kinds of directives as well that we call "structural" and "attribute" directives. - 有两种*其它*类型的指令,我们称之为“结构型”指令和“属性(attribute)型”指令。 + 有两种*其它*类型的指令,我们称之为“结构型”指令和“属性(attribute)型”指令。 They tend to appear within an element tag like attributes, sometimes by name but more often as the target of an assignment or a binding. - 它们往往像属性(attribute)一样出现在元素标签中,偶尔会以名字的形式出现(参见[一次性绑定](./template-syntax.html#one-time-initialization)),但多数时候还是作为赋值目标或绑定目标出现。 + 它们往往像属性(attribute)一样出现在元素标签中,偶尔会以名字的形式出现(参见[一次性绑定](./template-syntax.html#one-time-initialization)),但多数时候还是作为赋值目标或绑定目标出现。 **Structural** directives alter layout by adding, removing, and replacing elements in DOM. @@ -651,15 +651,15 @@ figure It modifies the behavior of an existing element (typically an ``) by setting its display value property and responding to change events. - 它修改了现有元素(典型的``)的行为:它设置了显示属性值,并对change事件做出相应回应。 + 它修改了现有元素(典型的``)的行为:它设置了显示属性值,并对change事件做出相应回应。 Angular ships with a few other directives that either alter the layout structure (e.g. [ngSwitch](template-syntax.html#ngSwitch)) or modify aspects of DOM elements and components (e.g. [ngStyle](template-syntax.html#ngStyle) and [ngClass](template-syntax.html#ngClass)). - Angular内置了一些其它指令,它们或者修改结构布局(如[ngSwitch](template-syntax.html#ngSwitch)),或者修改DOM元素和组件的各个方面 - (如[ngStyle](template-syntax.html#ngStyle)和[ngClass](template-syntax.html#ngClass))。 + Angular内置了一些其它指令,它们或者修改结构布局(如[ngSwitch](template-syntax.html#ngSwitch)),或者修改DOM元素和组件的各个方面 + (如[ngStyle](template-syntax.html#ngStyle)和[ngClass](template-syntax.html#ngClass))。 And of course we can write our own directives. @@ -750,7 +750,7 @@ figure and the application logic (which often includes some notion of a "model"). A good component presents properties and methods for data binding. It delegates everything non-trivial to services. - 组件的任务就是提供用户体验,仅此而已。它介于视图(由模板渲染)和应用逻辑(通常包括“模型model”的观念)之间。 + 组件的任务就是提供用户体验,仅此而已。它介于视图(由模板渲染)和应用逻辑(通常包括“模型model”的观念)之间。 设计良好的组件为数据绑定提供属性和方法,把那些其他对它们不重要的事情都委托给服务。 Angular doesn't *enforce* these principles. @@ -842,7 +842,7 @@ figure ... in which case we get a new instance of the service with each new instance of that component. - ... 在这种情况下,那个组件的每一个新实例都会有一个(在该组件注册的)服务的新实例。 + ... 在这种情况下,那个组件的每一个新实例都会有一个(在该组件注册的)服务的新实例。 We've vastly over-simplified dependency injection for this overview. We can learn the full story in the [Dependency Injection](dependency-injection.html) chapter. @@ -940,7 +940,7 @@ figure Most of them are covered in this Developers Guide (or soon will be): 这里是一个简短的、按字母排序的列表,列出了其它重要的Angular特性和服务。 - 它们大多数已经(或即将)包括在这个《开发指南》中: + 它们大多数已经(或即将)包括在这个《开发指南》中: >**Animations** - A forthcoming animation library makes it easy for developers to animate component behavior without deep knowledge of animation techniques or css. diff --git a/public/docs/ts/latest/guide/attribute-directives.jade b/public/docs/ts/latest/guide/attribute-directives.jade index 4c948b18df..f05914fae4 100644 --- a/public/docs/ts/latest/guide/attribute-directives.jade +++ b/public/docs/ts/latest/guide/attribute-directives.jade @@ -76,7 +76,7 @@ p 试用#[+liveExampleLink2("在线例子")]。 Besides, we're not just *setting* the color; we'll be *changing* the color in response to a user action, a mouse hover. - 再说,我们不仅要*设置*颜色,还要响应用户的动作(鼠标悬浮),来*更改*这个颜色。 + 再说,我们不仅要*设置*颜色,还要响应用户的动作(鼠标悬浮),来*更改*这个颜色。 .l-main-section a#write-directive @@ -570,12 +570,12 @@ a#why-input A property is a *source* if it appears in the template expression to the ***right*** of the equals (=). 在以前的所有绑定中,指令或组件的属性都是绑定***源***。 - 如果属性出现在了模板表达式等号(=)的***右侧***,它就是一个*源*。 + 如果属性出现在了模板表达式等号(=)的***右侧***,它就是一个*源*。 A property is a *target* when it appears in **square brackets** ([ ]) to the **left** of the equals (=) ... as it is does when we bind to the `myHighlight` property of the `HighlightDirective`, - 如果它出现在了**方括号**([ ])中,并且出现在等号(=)的**左侧**,它就是一个*目标*…… + 如果它出现在了**方括号**([ ])中,并且出现在等号(=)的**左侧**,它就是一个*目标*…… 就像在我们绑定到`HighlightDirective`的`myHighlight`属性时所做的那样。 +makeExample('attribute-directives/ts/app/app.component.html','pHost')(format=".") :marked @@ -609,7 +609,7 @@ a#why-input Not just the one or two properties we expected them to target. *Every* property. That could really mess up our directive in ways we didn't anticipate and have no desire to support. - 出乎意料的是,有些人(可能因为太天真)开始绑定到这个指令中的*每一个*属性。 + 出乎意料的是,有些人(可能因为太天真)开始绑定到这个指令中的*每一个*属性。 不仅仅是我们期望被作为目标使用的那一两个属性,而是*每一个*。 这可能会扰乱指令的工作方式 —— 我们既不想这样做也不想支持他们这样做。 diff --git a/public/docs/ts/latest/guide/cheatsheet-cn.json b/public/docs/ts/latest/guide/cheatsheet-cn.json index d611e056ae..5e43fb6ade 100644 --- a/public/docs/ts/latest/guide/cheatsheet-cn.json +++ b/public/docs/ts/latest/guide/cheatsheet-cn.json @@ -68,7 +68,7 @@ "bold": [ "(click)" ], - "description": "

当按钮(及其子元素)上的click事件被触发时,调用readRainbow方法,并把事件对象作为参数传入。

\n" + "description": "

当按钮(及其子元素)上的click事件被触发时,调用readRainbow方法,并把事件对象作为参数传入。

\n" }, { "syntax": "
", @@ -312,14 +312,14 @@ "bold": [ "@HostBinding('[class.valid]')" ], - "description": "

把宿主元素的属性(比如CSS类:valid)绑定到指令/组件的属性(比如:isValid)。

\n" + "description": "

把宿主元素的属性(比如CSS类:valid)绑定到指令/组件的属性(比如:isValid)。

\n" }, { "syntax": "@HostListener('click', ['$event']) onClick(e) {...}", "bold": [ "@HostListener('click', ['$event'])" ], - "description": "

通过指令/组件的方法(例如onClick)订阅宿主元素的事件(例如click),可选传入一个参数($event)。

\n" + "description": "

通过指令/组件的方法(例如onClick)订阅宿主元素的事件(例如click),可选传入一个参数($event)。

\n" }, { "syntax": "@ContentChild(myPredicate) myChildComponent;", @@ -483,42 +483,42 @@ "bold": [ "@CanActivate" ], - "description": "

用函数定义的一个组件装饰器,路由器会先调用它来检测是否应该激活该组件。应该返回布尔值或承诺(Promise)。

\n" + "description": "

用函数定义的一个组件装饰器,路由器会先调用它来检测是否应该激活该组件。应该返回布尔值或承诺(Promise)。

\n" }, { "syntax": "routerOnActivate(nextInstruction, prevInstruction) { ... }", "bold": [ "routerOnActivate" ], - "description": "

导航到一个组件之后,路由器调用该组件的routerOnActivate方法(如已定义)。

\n" + "description": "

导航到一个组件之后,路由器调用该组件的routerOnActivate方法(如已定义)。

\n" }, { "syntax": "routerCanReuse(nextInstruction, prevInstruction) { ... }", "bold": [ "routerCanReuse" ], - "description": "

路由器调用组件的routerCanReuse方法(如已定义)来检测是复用本实例还是销毁它并创建一个新的。应该返回布尔值或承诺(Promise)。

\n" + "description": "

路由器调用组件的routerCanReuse方法(如已定义)来检测是复用本实例还是销毁它并创建一个新的。应该返回布尔值或承诺(Promise)。

\n" }, { "syntax": "routerOnReuse(nextInstruction, prevInstruction) { ... }", "bold": [ "routerOnReuse" ], - "description": "

当路由器发现可以复用一个组件实例时,它调用组件的routerOnReuse方法(如已定义)。

\n" + "description": "

当路由器发现可以复用一个组件实例时,它调用组件的routerOnReuse方法(如已定义)。

\n" }, { "syntax": "routerCanDeactivate(nextInstruction, prevInstruction) { ... }", "bold": [ "routerCanDeactivate" ], - "description": "

路由器会调用如果要完成导航就得移除的每个组件的routerCanDeactivate方法(如已定义)。当且仅当所有的该方法都返回true或者承诺(Promise)被解决时,导航才会继续。

\n" + "description": "

路由器会调用如果要完成导航就得移除的每个组件的routerCanDeactivate方法(如已定义)。当且仅当所有的该方法都返回true或者承诺(Promise)被解决时,导航才会继续。

\n" }, { "syntax": "routerOnDeactivate(nextInstruction, prevInstruction) { ... }", "bold": [ "routerOnDeactivate" ], - "description": "

在每个指令因为路由变更而被移除之前调用。可以返回一个承诺,来阻止移除本指令 —— 直到承诺(Promise)被解决。

\n" + "description": "

在每个指令因为路由变更而被移除之前调用。可以返回一个承诺,来阻止移除本指令 —— 直到承诺(Promise)被解决。

\n" } ], "index": 10 diff --git a/public/docs/ts/latest/guide/component-styles.jade b/public/docs/ts/latest/guide/component-styles.jade index b6bc03b762..45e9b322f9 100644 --- a/public/docs/ts/latest/guide/component-styles.jade +++ b/public/docs/ts/latest/guide/component-styles.jade @@ -115,7 +115,7 @@ a(id="special-selectors") Use the `:host` pseudo-class selector to target styles in the element that *hosts* the component (as opposed to targeting elements *inside* the component's template): - 使用`:host`伪类选择器,用来选择组件*宿主*元素中的元素(相对于组件模板*内部*的元素)。 + 使用`:host`伪类选择器,用来选择组件*宿主*元素中的元素(相对于组件模板*内部*的元素)。 +makeExample('component-styles/ts/app/hero-details.component.css', 'host')(format='.') @@ -146,7 +146,7 @@ a(id="special-selectors") we want to change how our component looks based on that. 有时候,基于某些来自组件视图*外部*的条件应用样式是很有用的。 - 比如,在文档的``元素上可能有一个用于表示样式主题(Theme)的CSS类,而我们应当基于它来决定组件的样式。 + 比如,在文档的``元素上可能有一个用于表示样式主题(Theme)的CSS类,而我们应当基于它来决定组件的样式。 Use the `:host-context()` pseudo-class selector. It works just like the function form of `:host()`. It looks for a CSS class in *any ancestor* of the component host element, all the way @@ -224,7 +224,7 @@ a(id='loading-styles') Each string in the #{_array} (usually just one string) defines the CSS. 我们可以给`@Component`#{_decoratorCn}添加一个`styles`数组型属性。 - 这个数组中的每一个字符串(通常也只有一个)定义一份CSS。 + 这个数组中的每一个字符串(通常也只有一个)定义一份CSS。 +makeExample('component-styles/ts/app/hero-app.component.ts') @@ -349,8 +349,8 @@ a#view-encapsulation (and renaming) the CSS code to effectively scope the CSS to the component's view. See [Appendix 1](#inspect-generated-css) for details. - * `Emulated`模式(**默认值**)通过预处理(并改名)CSS代码来仿真Shadow DOM的行为,以达到把CSS样式局限在组件视图中的目的。 - 参见[附录1](#inspect-generated-css)了解详情。(译注:只进不出,全局样式能进来,组件样式出不去) + * `Emulated`模式(**默认值**)通过预处理(并改名)CSS代码来仿真Shadow DOM的行为,以达到把CSS样式局限在组件视图中的目的。 + 参见[附录1](#inspect-generated-css)了解详情。(译注:只进不出,全局样式能进来,组件样式出不去) * `None` means that Angular does no view encapsulation. Angular adds the CSS to the global styles. @@ -358,7 +358,7 @@ a#view-encapsulation This is essentially the same as pasting the component's styles into the HTML. * `None`意味着Angular不使用视图包装。 Angular会把CSS添加到全局样式中。而不会应用上前面讨论过的那些局限化规则、隔离和保护等规则。 - 从本质上来说,这跟把组件的样式直接放进HTML是一样的。(译注:能进能出。) + 从本质上来说,这跟把组件的样式直接放进HTML是一样的。(译注:能进能出。) Set the components encapsulation mode using the `encapsulation` property in the component metadata: diff --git a/public/docs/ts/latest/guide/dependency-injection.jade b/public/docs/ts/latest/guide/dependency-injection.jade index ba4f66b03e..9b6fc90142 100644 --- a/public/docs/ts/latest/guide/dependency-injection.jade +++ b/public/docs/ts/latest/guide/dependency-injection.jade @@ -222,7 +222,7 @@ block ctor-syntax We could write a giant class to do that: - 我们可以写一个巨型类来做这件事(不好的模式): + 我们可以写一个巨型类来做这件事(不好的模式): +makeExample('dependency-injection/ts/app/car/car-factory.ts', null, 'app/car/car-factory.ts') @@ -375,7 +375,7 @@ block ctor-syntax 我们甚至没有假装这是一个真实的服务。 如果我们真的从一个远端服务器获取数据,这个API必须是异步的,可能得返回 - [ES2015 承诺(Promise)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)。 + [ES2015 承诺(Promise)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)。 我们也需要被迫重新处理组件如何消费该服务的方式。通常这个很重要,但是我们目前的故事不需要。 :marked @@ -495,7 +495,7 @@ block ctor-syntax has `providers` information for `HeroService`. 注意构造函数参数有类型`HeroService`,并且`HeroListComponent`类有一个`@Component`装饰器 - (往上翻可以确认)。另外,记得父级组件(`HeroesComponent`)有`HeroService`的`providers`信息。 + (往上翻可以确认)。另外,记得父级组件(`HeroesComponent`)有`HeroService`的`providers`信息。 The constructor parameter type, the `@Component` #{_decorator}, and the parent's `providers` information combine to tell the @@ -658,7 +658,7 @@ block injectable-not-always-needed-in-ts fact `InjectableMetadata` #{_decorator}s that identify a class as a target for instantiation by an injector. - 如果真的想要这样做,我们*可以*添加它。但是这不是必须的,因为`HerosComponent`已经被`@Component`标识,这个装饰器类(像`@Directive`和`@Pipe`一样,我们一会儿将会学到) + 如果真的想要这样做,我们*可以*添加它。但是这不是必须的,因为`HerosComponent`已经被`@Component`标识,这个装饰器类(像`@Directive`和`@Pipe`一样,我们一会儿将会学到) 是一个InjectableMetadata的子类型。实际上,`InjectableMetadata`装饰器标识着一个类是注入器实例化的目标。 @@ -730,7 +730,7 @@ block real-logger code-example(format="nocode"). EXCEPTION: No provider for Logger! (HeroListComponent -> HeroService -> Logger) - (异常:Logger类没有供应商!(HeroListComponent -> HeroService -> Logger)) + (异常:Logger类没有供应商!(HeroListComponent -> HeroService -> Logger)) :marked That's Angular telling us that the dependency injector couldn't find the *provider* for the logger. @@ -862,7 +862,7 @@ block dart-diff-const-metadata This logger gets the user from the injected `UserService`, which happens also to be injected at the application level. - 也许一个`EvenBetterLogger`(更好的日志)可以在日志消息中显示用户名。 + 也许一个`EvenBetterLogger`(更好的日志)可以在日志消息中显示用户名。 这个日志服务从一个注入进来的`UserService`中取得用户,`UserService`通常也会在应用级被注入。 +makeExample('dependency-injection/ts/app/providers.component.ts','EvenBetterLogger')(format='.') @@ -1125,7 +1125,7 @@ block dart-diff-const-metadata-ctor the address of a web API endpoint)  but these configuration objects aren't always instances of a class. They can be object literals  such as this one: - 应用程序经常为很多很小的因素(比如应用程序的标题,或者一个网络API终点的地址)定义配置对象,但是这些配置对象不总是类的实例。 + 应用程序经常为很多很小的因素(比如应用程序的标题,或者一个网络API终点的地址)定义配置对象,但是这些配置对象不总是类的实例。 他们可能是对象,比如下面这个: +makeExample('dependency-injection/ts/app/app.config.ts','config','app/app-config.ts (excerpt)')(format='.') @@ -1180,7 +1180,7 @@ block what-should-we-use-as-token to define and use an !{opaquetoken}. The definition looks like this: - 解决方案是定义和使用一个!{opaquetoken}(不透明的令牌)。定义方式类似于这样: + 解决方案是定义和使用一个!{opaquetoken}(不透明的令牌)。定义方式类似于这样: +makeExample('dependency-injection/ts/app/app.config.ts','token')(format='.') @@ -1250,7 +1250,7 @@ block dart-map-alternative adding a parameter to a constructor. 在本章中,我们学习了Angular依赖注入的基础。 - 我们可以注册很多种类的供应商,还知道了该如何通过添加构造函数的参数来请求一个被注入对象(比如服务)。 + 我们可以注册很多种类的供应商,还知道了该如何通过添加构造函数的参数来请求一个被注入对象(比如服务)。 Angular dependency injection is more capable than we've described. We can learn more about its advanced features, beginning with its support for @@ -1296,7 +1296,7 @@ block dart-map-alternative to retrieve a service (`ROUS`) that isn't registered with this or any ancestor injector. `get`方法如果解析不出所请求的服务,它就会抛出一个异常。 - 我们还可以带上第二个参数(如果服务没找到,就把它作为默认值返回)调用`get`, + 我们还可以带上第二个参数(如果服务没找到,就把它作为默认值返回)调用`get`, 在该例子中,我们获取了一个服务(`ROUS`),它没有在这个注入器或它的任何祖先中注册过。 .l-sub-section :marked diff --git a/public/docs/ts/latest/guide/displaying-data.jade b/public/docs/ts/latest/guide/displaying-data.jade index 7720f539bb..994fb7e11c 100644 --- a/public/docs/ts/latest/guide/displaying-data.jade +++ b/public/docs/ts/latest/guide/displaying-data.jade @@ -132,7 +132,7 @@ include ../_quickstart_repo We're ready to see changes in a running app by firing up the npm script that both compiles and serves our applications while watching for changes. - 通过运行npm脚本(它能编译并启动一个能监视文件变化的服务器),我们能看到运行中的应用发生的变化。 + 通过运行npm脚本(它能编译并启动一个能监视文件变化的服务器),我们能看到运行中的应用发生的变化。 code-example(format=""). npm start :marked @@ -241,13 +241,13 @@ figure.image-display it is an example of a [template input variable](./template-syntax.html#ngForMicrosyntax). 注意看`ngFor`双引号表达式中的`hero`。 - 它是一个[模板输入变量](./template-syntax.html#ngForMicrosyntax)(译注:即ngFor模板中从外界输入的变量)。 + 它是一个[模板输入变量](./template-syntax.html#ngForMicrosyntax)(译注:即ngFor模板中从外界输入的变量)。 Angular duplicates the `
  • ` for each item in the list, setting the `hero` variable to the item (the hero) in the current iteration. Angular uses that variable as the context for the interpolation in the double curly braces. - Angular为列表中的每一个条目复制一个`
  • `元素。在每个迭代中,都会把`hero`变量设置为当前条目(此英雄)。 + Angular为列表中的每一个条目复制一个`
  • `元素。在每个迭代中,都会把`hero`变量设置为当前条目(此英雄)。 Angular把`hero`变量作为双花括号插值表达式的上下文。 .l-sub-section :marked diff --git a/public/docs/ts/latest/guide/forms.jade b/public/docs/ts/latest/guide/forms.jade index bea9a62ea0..5aab2713a8 100644 --- a/public/docs/ts/latest/guide/forms.jade +++ b/public/docs/ts/latest/guide/forms.jade @@ -72,7 +72,7 @@ include ../_util-fns :marked That's not the only way to create a form but it's the way we'll cover in this chapter. - 这不是创建表单的唯一方式,但它是我们将在本章中使用的方式。(译注:Angular支持的另一种方式叫做模型驱动表单Model-Driven Forms) + 这不是创建表单的唯一方式,但它是我们将在本章中使用的方式。(译注:Angular支持的另一种方式叫做模型驱动表单Model-Driven Forms) :marked We can build almost any form we need with an Angular template — login forms, contact forms ... pretty much any business forms. @@ -169,7 +169,7 @@ figure.image-display Create a new project folder (`angular2-forms`) and follow the steps in the [QuickStart](../quickstart.html). - 创建一个新的项目文件夹(`angular2-forms`),并且完成[“快速起步”](../quickstart.html)中的步骤。 + 创建一个新的项目文件夹(`angular2-forms`),并且完成[“快速起步”](../quickstart.html)中的步骤。 include ../_quickstart_repo :marked @@ -188,7 +188,7 @@ include ../_quickstart_repo and one optional field (`alterEgo`). 最简单的模型就是一个“属性包”,用来存放应用中一件事物的事实。 - 这里我们使用三个必备字段(`id`、`name`、`power`),和一个可选字段(`alterEgo`,译注:中文含义:第二人格,比如X战警中的Jean/黑凤凰)。 + 这里我们使用三个必备字段(`id`、`name`、`power`),和一个可选字段(`alterEgo`,译注:中文含义:第二人格,比如X战警中的Jean/黑凤凰)。 Create a new file in the app folder called `hero.ts` and give it the following class definition: @@ -208,7 +208,7 @@ include ../_quickstart_repo The `alterEgo` is optional and the constructor lets us omit it; note the (?) in `alterEgo?`. - `alterEgo`是可选的,构造函数允许我们省略它,注意`alterEgo?`中的问号(?)。 + `alterEgo`是可选的,构造函数允许我们省略它,注意`alterEgo?`中的问号(?)。 We can create a new hero like this: @@ -287,7 +287,7 @@ code-example(format=""). We also like short files with a clear and obvious purpose like this one. 没有什么答案在所有场合都总是“正确”的。当内联模板足够短的时候,我们更喜欢用它。 - 但大多数的表单模板都不短。普遍来讲,TypeScript和JavaScript文件不是写大型HTML的好地方(也不好读)。 + 但大多数的表单模板都不短。普遍来讲,TypeScript和JavaScript文件不是写大型HTML的好地方(也不好读)。 而且没有几个编辑器能对混写的HTML和代码提供足够的帮助。 我们还是喜欢写成像这个一样清晰明确的短文件。 @@ -331,7 +331,7 @@ code-example(format=""). 1. The `directives` array tells Angular that our template depends upon the `HeroFormComponent` which is itself a Directive (as are all Components). - 1. `directives`数组告诉Angular,我们的模板依赖于`HeroFormComponent`组件,它本身也是一个指令(所有组件都是指令)。 + 1. `directives`数组告诉Angular,我们的模板依赖于`HeroFormComponent`组件,它本身也是一个指令(所有组件都是指令)。 .l-main-section :marked @@ -612,7 +612,7 @@ figure.image-display the event handling such as debounce or throttle the key strokes. 很高兴知道这些,但是这样现实吗?实践上我们几乎总是优先使用`[(ngModel)]`形式的双向绑定。 - 只有当我们不得不在事件处理函数中做一些特别的事情(比如合并或限制按键频率)时,才需要拆分出独立的事件处理函数。 + 只有当我们不得不在事件处理函数中做一些特别的事情(比如合并或限制按键频率)时,才需要拆分出独立的事件处理函数。 Learn more about `NgModel` and other template syntax in the [Template Syntax](./template-syntax.html) chapter. @@ -670,7 +670,7 @@ figure.image-display 我们模板中的这个`ngControl`*属性*实际上被映射到了 [NgControlName](../api/common/index/NgControlName-directive.html)指令。 虽然还有另一个叫`NgControl`的*抽象*指令,但和这个属性不是一回事。 - 我们通常会忽略这点技术上的差异。为了更方便(尽管不正确),我们提起`NgControlName`时还是会把它叫做*NgControl*指令。 + 我们通常会忽略这点技术上的差异。为了更方便(尽管不正确),我们提起`NgControlName`时还是会把它叫做*NgControl*指令。 While we're under the hood, we might as well note that the `ngModel` in the two-way binding syntax is now a property of the `NgControlName` directive. @@ -894,7 +894,7 @@ figure.image-display 这种用户体验取决于开发人员的选择。有些人会希望任何时候都显示这条消息。 如果忽略了`pristine`状态,我们就会只在值有效时隐藏此消息。 - 如果往这个组件中传入一个全新(空白)的英雄,或者一个无效的英雄,我们将立刻看到错误信息 —— 虽然我们还啥都没做。 + 如果往这个组件中传入一个全新(空白)的英雄,或者一个无效的英雄,我们将立刻看到错误信息 —— 虽然我们还啥都没做。 Some folks find that behavior disconcerting. They only want to see the message when the user makes an invalid change. Hiding the message while the control is "pristine" achieves that goal. @@ -951,7 +951,7 @@ figure.image-display This time we see an error message! Why? We don't want that when we display a new (empty) hero. 输入一个名字,并再次点击*新增英雄*按钮。 - 这次,我们看到了错误信息!为什么?当我们显示一个新(空白)的英雄时,我们不希望如此。 + 这次,我们看到了错误信息!为什么?当我们显示一个新(空白)的英雄时,我们不希望如此。 Inspecting the element in the browser tools reveals that the *name* input box is no longer pristine. Replacing the hero *did not restore the pristine state* of the control. @@ -1092,7 +1092,7 @@ figure.image-display :marked ## Toggle two form regions (extra credit) - ## 切换两个表单区域(额外的荣誉) + ## 切换两个表单区域(额外的荣誉) Submitting the form isn't terribly dramatic at the moment. diff --git a/public/docs/ts/latest/guide/hierarchical-dependency-injection.jade b/public/docs/ts/latest/guide/hierarchical-dependency-injection.jade index 1e72f7ddf4..681b5c0d55 100644 --- a/public/docs/ts/latest/guide/hierarchical-dependency-injection.jade +++ b/public/docs/ts/latest/guide/hierarchical-dependency-injection.jade @@ -14,7 +14,7 @@ block includes interesting and useful results. Angular有一个多级依赖注入系统。 - 实际上,应用程序中有一个与组件树平行的注入器树(译注:平行是指结构完全相同且一一对应)。 + 实际上,应用程序中有一个与组件树平行的注入器树(译注:平行是指结构完全相同且一一对应)。 我们可以在组件树中的任何级别上重新配置注入器,达到一些有趣和有用的效果。 In this chapter we explore these points and write some code. @@ -58,7 +58,7 @@ p 试试#[+liveExampleLink2("在线例子")]. But it is true that every component ***has an injector*** (even if it shares that injector with another component) and there may be many different injector instances operating at different levels of the component tree. - 但是,每个组件都**有一个注入器**是真实的(就算它与其它组件共享注入器,也是*有注入器*),并且确实可能会有大量不同的注入器实例工作在组件树的不同级别。 + 但是,每个组件都**有一个注入器**是真实的(就算它与其它组件共享注入器,也是*有注入器*),并且确实可能会有大量不同的注入器实例工作在组件树的不同级别。 It is useful to pretend that every component has its own injector. @@ -129,9 +129,9 @@ figure.image-display This child is the parent of another component (C) that defines its own provider for `Car`. 让我们回到“汽车(Car)”类的例子。 - 假设“根注入器”(记为A)配置过`Car`、`Engine`和`Tires`的供应商。 - 然后创建了一个子组件(B),它为`Car`和`Engine`类定义了自己的供应商。 - 这个子组件(B)又有另一个子组件(C),(C)也为`Car`定义了自己的供应商。 + 假设“根注入器”(记为A)配置过`Car`、`Engine`和`Tires`的供应商。 + 然后创建了一个子组件(B),它为`Car`和`Engine`类定义了自己的供应商。 + 这个子组件(B)又有另一个子组件(C),(C)也为`Car`定义了自己的供应商。 Behind the scenes each component sets up its own injector with one or more providers defined for that component itself. @@ -141,8 +141,8 @@ figure.image-display its injector produces an instance of `Car` resolved by injector (C) with an `Engine` resolved by injector (B) and `Tires` resolved by the root injector (A). - 当我们在最底层的组件(C)中试图解析出一个`Car`的实例时,注入器(C)解析出的`Car`类的实例, - 该`Car`的实例带有一个`Engine`类的实例(由注入器(B)解析出)和一个`Tires`类的实例(由跟注入器(A)解析出)。 + 当我们在最底层的组件(C)中试图解析出一个`Car`的实例时,注入器(C)解析出的`Car`类的实例, + 该`Car`的实例带有一个`Engine`类的实例(由注入器(B)解析出)和一个`Tires`类的实例(由跟注入器(A)解析出)。 figure.image-display img(src="/resources/images/devguide/dependency-injection/injector-tree.png" alt="injector tree" width="600") @@ -277,7 +277,7 @@ figure.image-display scoped to that component instance and its child components. 但很明显,这个场景下我们不希望这样。我们希望每个组件都有它自己的`RestoreService`实例。 - 在组件级别上定义(或重定义)一个供应商,将会为该组件创建一个新的服务实例。 + 在组件级别上定义(或重定义)一个供应商,将会为该组件创建一个新的服务实例。 我们已经为`HeroEditComponent`制造了一种“私有”`RestoreService`单例,它的作用范围被局限在了该组件的实例及其子组件中。