[
{
"original": "## Transpile",
"translation": "## 转译(transpile)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/_fragments/glossary-t2.md"
},
{
"original": "The process of transforming code written in one form of JavaScript\n(such as TypeScript) into another form of JavaScript (such as [ES5](_fragments/glossary-t2#es5)).",
"translation": "把一种形式的 JavaScript(例如 TypeScript)转换成另一种形式的 JavaScript(例如 [ES5](_fragments/glossary-t2#es5))的过程。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/_fragments/glossary-t2.md"
},
{
"original": "## TypeScript",
"translation": "## TypeScript 语言",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/_fragments/glossary-t2.md"
},
{
"original": "A version of JavaScript that supports most [ECMAScript 2015](_fragments/glossary-t2#es2015)\nlanguage features such as [decorators](_fragments/glossary-t2#decorator).",
"translation": "JavaScript 的一个版本,支持了几乎所有 [ECMAScript 2015](_fragments/glossary-t2#ecmascript=2015) 语言特性,例如[装饰器 (decorator)](_fragments/glossary-t2#decorator))。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/_fragments/glossary-t2.md"
},
{
"original": "TypeScript is also notable for its optional typing system, which provides\ncompile-time type checking and strong tooling support (such as \"intellisense,\"\ncode completion, refactoring, and intelligent search). Many code editors\nand IDEs support TypeScript either natively or with plugins.",
"translation": "TypeScript 还以它的可选类型系统而著称。\n该类型系统提供了编译时类型检查和强大的工具支持(例如 “Intellisense”,代码补齐,重构和智能搜索等)。\n许多代码编辑器和 IDE 都原生支持 TypeScript 或通过插件提供支持。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/_fragments/glossary-t2.md"
},
{
"original": "TypeScript is the preferred language for Angular development, although\nyou can use other JavaScript dialects such as [ES5](_fragments/glossary-t2#es5).",
"translation": "TypeScript 是 Angular 的首选语言,当然,你可以使用其它 JavaScript 方言,例如[ES5](_fragments/glossary-t2#es5)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/_fragments/glossary-t2.md"
},
{
"original": "Read more about TypeScript at [typescriptlang.org](http://www.typescriptlang.org/).",
"translation": "更多信息,见[typescript.org](http://www.typescriptlang.org/)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/_fragments/glossary-t2.md"
},
{
"original": "# AngularJS to Angular Quick Reference",
"translation": "# 从 AngularJS 到 Angular 快速参考",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "_Angular_ is the name for the Angular of today and tomorrow.\n_AngularJS_ is the name for all v1.x versions of Angular.",
"translation": "*Angular*这个名字专指现在和未来的Angular版本,而*AngularJS*专指Angular的所有v1.x版本。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "This guide helps you transition from AngularJS to Angular\nby mapping AngularJS syntax to the equivalent Angular syntax.",
"translation": "本章提供了一个快速的参考指南,指出一些常用的AngularJS语法及其在Angular中的等价物。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "**See the Angular syntax in this **.",
"translation": "**参见 以学习 Angular 语法**",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "## Template basics",
"translation": "## 模板基础",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Templates are the user-facing part of an Angular application and are written in HTML.\nThe following table lists some of the key AngularJS template features with their equivalent Angular template syntax.",
"translation": "模板是Angular应用中的门面部分,它是用HTML写的。下表中是一些AngularJS中的关键模板特性及其在Angular中的等价语法。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Bindings/interpolation",
"translation": "### 绑定/插值表达式",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, an expression in curly braces denotes one-way binding.\n This binds the value of the element to a property in the controller\n associated with this template.",
"translation": "在AngularJS中,花括号中的表达式代表单向绑定。\n 它把元素的值绑定到了与模板相关控制器的属性上。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "When using the `controller as` syntax,\n the binding is prefixed with the controller alias (`vm` or `$ctrl`) because you\n have to be specific about the source of the binding.",
"translation": "当使用`controller as`语法时,该绑定需要用控制器的别名(`vm`)为前缀,这是因为我们不得不通过它来指定绑定源。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Bindings/interpolation",
"translation": "### 绑定/插值表达式",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, a template expression in curly braces still denotes one-way binding.\n This binds the value of the element to a property of the component.\n The context of the binding is implied and is always the\n associated component, so it needs no reference variable.",
"translation": "在Angular中,花括号中的模板表达式同样代表单向绑定。\n 它把元素的值绑定到了组件的属性上。\n 它绑定的上下文变量是隐式的,并且总是关联到组件。\n 所以,它不需要一个引用变量。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information, see the [Interpolation](guide/template-syntax#interpolation)\n section of the [Template Syntax](guide/template-syntax) page.",
"translation": "要了解更多,请参见[模板语法](guide/template-syntax)中的[插值表达式](guide/template-syntax#interpolation)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Filters",
"translation": "### 过滤器",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "To filter output in AngularJS templates, use the pipe character (|) and one or more filters.",
"translation": "要在AngularJS中过滤输出,使用管道字符(|)以及一个或多个过滤器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "This example filters the `title` property to uppercase.",
"translation": "这个例子中把`title`属性过滤成了大写形式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Pipes",
"translation": "### 管道",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In Angular you use similar syntax with the pipe (|) character to filter output, but now you call them **pipes**.\n Many (but not all) of the built-in filters from AngularJS are\n built-in pipes in Angular.",
"translation": "在Angular中,我们使用相似的语法 —— 用管道字符(|)来过滤输出,但是现在直接把它叫做**管道**了。\n 很多(但不是所有)AngularJS中的内置过滤器也成了Angular中的内置管道。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information, see [Filters/pipes](guide/ajs-quick-reference#filters-pipes) below.",
"translation": "请参见下面[过滤器/管道](guide/ajs-quick-reference#filters-pipes)了解更多信息。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Local variables",
"translation": "### 局部变量",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Here, `movie` is a user-defined local variable.",
"translation": "这里的`movie`是一个用户定义的局部变量",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Input variables",
"translation": "### 输入变量",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Angular has true template input variables that are explicitly defined using the `let` keyword.",
"translation": "Angular 有了真正的模板输入变量,它需要使用`let`关键字进行明确定义。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information, see the [ngFor micro-syntax](guide/template-syntax#microsyntax)\n section of the [Template Syntax](guide/template-syntax) page.",
"translation": "要了解更多信息,请参见[模板语法](guide/template-syntax)中的[ngFor微语法](guide/template-syntax#microsyntax)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "## Template directives",
"translation": "## 模板指令",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "AngularJS provides more than seventy built-in directives for templates.\nMany of them aren't needed in Angular because of its more capable and expressive binding system.\nThe following are some of the key AngularJS built-in directives and their equivalents in Angular.",
"translation": "AngularJS 为模板提供了七十多个内置指令。\n在 Angular 中,它们很多都已经不需要了,因为 Angular 有了一个更加强大、快捷的绑定系统。\n下面是一些AngularJS 中的关键指令及其在 Angular 中的等价物。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The application startup process is called **bootstrapping**.",
"translation": "应用的启动过程被称为**引导**。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Although you can bootstrap an AngularJS app in code,\n many applications bootstrap declaratively with the `ng-app` directive,\n giving it the name of the application's module (`movieHunter`).",
"translation": "虽然可以从代码中引导Angular应用,\n 但很多应用都是通过`ng-app`指令进行声明式引导的,只要给它一个应用模块的名字(`movieHunter`)就可以了。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Bootstrapping",
"translation": "### 引导",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Angular doesn't have a bootstrap directive.\n To launch the app in code, explicitly bootstrap the application's root module (`AppModule`)\n in `main.ts`\n and the application's root component (`AppComponent`) in `app.module.ts`.",
"translation": "Angular 没有引导指令。\n 总是要通过显式调用一个`bootstrap`函数,并传入应用模块的名字(`AppComponent`)来启动应用。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, the `ng-class` directive includes/excludes CSS classes\n based on an expression. That expression is often a key-value control object with each\n key of the object defined as a CSS class name, and each value defined as a template expression\n that evaluates to a Boolean value.",
"translation": "在AngularJS中,`ng-class`指令会基于一个表达式来包含/排除某些CSS类。该表达式通常是一个“键-值”型的控制对象,\n 对象中的每一个键代表一个CSS类名,每一个值定义为一个返回布尔值的模板表达式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In the first example, the `active` class is applied to the element if `isActive` is true.",
"translation": "在第一个例子中,如果`isActive`为真,则`active`类被应用到那个元素上。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "You can specify multiple classes, as shown in the second example.",
"translation": "就像第二个例子中所展示的那样,可以同时指定多个类。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, the `ngClass` directive works similarly.\n It includes/excludes CSS classes based on an expression.",
"translation": "在Angular中,`ngClass`指令用类似的方式工作。\n 它根据一个表达式包含/排除某些CSS类。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In the first example, the `active` class is applied to the element if `isActive` is true.",
"translation": "在第一个例子中,如果`isActive`为真,则`active`类被应用到那个元素上。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "You can specify multiple classes, as shown in the second example.",
"translation": "就像第二个例子中所展示的那样,可以同时指定多个类。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Angular also has **class binding**, which is a good way to add or remove a single class,\n as shown in the third example.",
"translation": "Angular还有**类绑定**,它是单独添加或移除一个类的好办法 —— 就像第三个例子中展示的。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information see the [Attribute, class, and style bindings](guide/template-syntax#other-bindings)\n section of the [Template Syntax](guide/template-syntax) page.",
"translation": "要了解更多信息,参见[模板语法](guide/template-syntax)中的[属性、CSS类和样式绑定](guide/template-syntax#other-bindings)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, the `ng-click` directive allows you to specify custom behavior when an element is clicked.",
"translation": "在AngularJS中,`ng-click`指令指定当元素被点击时的自定义行为。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In the first example, when the user clicks the button, the `toggleImage()` method in the controller referenced by the `vm` `controller as` alias is executed.",
"translation": "在第一个例子中,如果用户点击了这个按钮,那么控制器的`toggleImage()`方法就会被执行,这个控制器是被`controller as`中指定的`vm`别名所引用的。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The second example demonstrates passing in the `$event` object, which provides details about the event\n to the controller.",
"translation": "第二个例子演示了传入`$event`对象,它提供了事件的详情,并被传到控制器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Bind to the `click` event",
"translation": "### 绑定到`click`事件",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "AngularJS event-based directives do not exist in Angular.\n Rather, define one-way binding from the template view to the component using **event binding**.",
"translation": "AngularJS基于事件的指令在Angular中已经不存在了。\n 不过,可以使用**事件绑定**来定义从模板视图到组件的单向数据绑定。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For event binding, define the name of the target event within parenthesis and\n specify a template statement, in quotes, to the right of the equals. Angular then\n sets up an event handler for the target event. When the event is raised, the handler\n executes the template statement.",
"translation": "要使用事件绑定,把目标事件的名字放在圆括号中,并且使用等号右侧引号中的模板语句对它赋值。\n 然后Angular为这个目标时间设置事件处理器。当事件被触发时,这个处理器就会执行模板语句。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In the first example, when a user clicks the button, the `toggleImage()` method in the associated component is executed.",
"translation": "在第一个例子中,当用户点击此按钮时,相关组件中的`toggleImage()`方法就被执行了。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The second example demonstrates passing in the `$event` object, which provides details about the event\n to the component.",
"translation": "第二个例子演示了如何传入`$event`对象,它为组件提供了此事件的详情。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For a list of DOM events, see: https://developer.mozilla.org/en-US/docs/Web/Events.",
"translation": "要查看DOM事件的列表,请参见[网络事件](https://developer.mozilla.org/en-US/docs/Web/Events)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information, see the [Event binding](guide/template-syntax#event-binding)\n section of the [Template Syntax](guide/template-syntax) page.",
"translation": "要了解更多,请参见[模板语法](guide/template-syntax)中的[事件绑定](guide/template-syntax#event-binding)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, the `ng-controller` directive attaches a controller to the view.\n Using the `ng-controller` (or defining the controller as part of the routing) ties the\n view to the controller code associated with that view.",
"translation": "在AngularJS中,`ng-controller`指令把控制器附加到视图上。\n 使用`ng-controller`(或把控制器定义为路由的一部分)把视图及其控制器的代码联系在一起。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Component decorator",
"translation": "### 组件装饰器",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, the template no longer specifies its associated controller.\n Rather, the component specifies its associated template as part of the component class decorator.",
"translation": "在Angular中,模板不用再指定它相关的控制器。\n 反过来,组件会在组件类的装饰器中指定与它相关的模板。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information, see [Architecture Overview](guide/architecture#components).",
"translation": "要了解更多,请参见[架构概览](guide/architecture#components)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, the `ng-hide` directive shows or hides the associated HTML element based on\n an expression. For more information, see [ng-show](guide/ajs-quick-reference#ng-show).",
"translation": "在AngularJS中,`ng-hide`指令会基于一个表达式显示或隐藏相关的HTML元素。\n 参见[ng-show](guide/ajs-quick-reference#ng-show)了解更多。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Bind to the `hidden` property",
"translation": "### 绑定到`hidden`属性",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, you use property binding; there is no built-in *hide* directive.\n For more information, see [ng-show](guide/ajs-quick-reference#ng-show).",
"translation": "在Angular中,并没有一个内置的*hide*指令,可以改用属性绑定。\n 参见[ng-show](guide/ajs-quick-reference#ng-show)了解更多。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The `ng-href` directive allows AngularJS to preprocess the `href` property so that it\n can replace the binding expression with the appropriate URL before the browser\n fetches from that URL.",
"translation": "`ng-href`指令允许AngularJS对`href`属性进行预处理,以便它能在浏览器获取那个URL之前,使用一个返回适当URL的绑定表达式替换它。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, the `ng-href` is often used to activate a route as part of navigation.",
"translation": "在AngularJS 中,`ng-href`通常用来作为导航的一部分,激活一个路由。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Routing is handled differently in Angular.",
"translation": "路由在Angular中的处理方式不同。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Bind to the `href` property",
"translation": "### 绑定到`href`属性",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Angular uses property binding; there is no built-in *href* directive.\n Place the element's `href` property in square brackets and set it to a quoted template expression.",
"translation": "在Angular中,并没有内置的*href*指令,改用属性绑定。\n 我们把元素的`href`属性放在方括号中,并把它设成一个引号中的模板表达式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information see the [Property binding](guide/template-syntax#property-binding)\n section of the [Template Syntax](guide/template-syntax) page.",
"translation": "要了解[属性绑定](guide/template-syntax#property-binding)的更多知识,参见[模板语法](guide/template-syntax)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, `href` is no longer used for routing. Routing uses `routerLink`, as shown in the following example.",
"translation": "在Angular中,`href`不再用作路由,而是改用第三个例子中所展示的`routerLink`指令。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information on routing, see the [RouterLink binding](guide/router#router-link)\n section of the [Routing & Navigation](guide/router) page.",
"translation": "要了解关于路由的更多信息,请参见[路由与导航](guide/router)的[RouterLink绑定](guide/router#router-link)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, the `ng-if` directive removes or recreates a portion of the DOM,\n based on an expression. If the expression is false, the element is removed from the DOM.",
"translation": "在AngularJS中,`ng-if`指令会根据一个表达式来移除或重建DOM中的一部分。如果表达式为假,元素就会被从DOM中移除。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In this example, the `
` element is removed from the DOM unless the `movies` array has a length greater than zero.",
"translation": "在这个例子中,除非`movies`数组的长度大于0,否则`
`元素就会被从DOM中移除。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The `*ngIf` directive in Angular works the same as the `ng-if` directive in AngularJS. It removes\n or recreates a portion of the DOM based on an expression.",
"translation": "Angular中的`*ngIf`指令与AngularJS中的`ng-if`指令一样,\n 它根据表达式的值移除或重建DOM中的一部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In this example, the `
` element is removed from the DOM unless the `movies` array has a length.",
"translation": "在这个例子中,除非`movies`数组的长度大于0,否则`
`元素就会被从DOM中移除。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The (*) before `ngIf` is required in this example.\n For more information, see [Structural Directives](guide/structural-directives).",
"translation": "在这个例子中`ngIf`前的星号(*)是必须的。\n 要了解更多信息,参见[结构型指令](guide/structural-directives)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, the `ng-model` directive binds a form control to a property in the controller associated with the template.\n This provides **two-way binding**, whereby any change made to the value in the view is synchronized with the model, and any change to the model is synchronized with the value in the view.",
"translation": "在Angular1中,`ng-model`指令把一个表单控件绑定到了模板相关控制器的一个属性上。\n 这提供了**双向绑定**功能,因此,任何对视图中值的改动,都会同步到模型中,对模型的改动,也会同步到视图中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, **two-way binding** is denoted by `[()]`, descriptively referred to as a \"banana in a box\". This syntax is a shortcut for defining both property binding (from the component to the view)\n and event binding (from the view to the component), thereby providing two-way binding.",
"translation": "在Angular中,**双向绑定**使用[()]标记出来,它被形象的比作“盒子中的香蕉”。\n 这种语法是一个简写形式,用来同时定义一个属性绑定(从组件到视图)和一个事件绑定(从视图到组件),因此,我们得到了双向绑定。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information on two-way binding with `ngModel`, see the [NgModel—Two-way binding to\n form elements with `[(ngModel)]`](../guide/template-syntax.html#ngModel)\n section of the [Template Syntax](guide/template-syntax) page.",
"translation": "要了解使用ngModel进行双向绑定的更多知识,参见[模板语法](guide/template-syntax)中的[NgModel—使用`[(ngModel)]`进行双向绑定](../guide/template-syntax.html#ngModel)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, the `ng-repeat` directive repeats the associated DOM element\n for each item in the specified collection.",
"translation": "在Angular1中,`ng-repeat`指令会为指定集合中的每一个条目重复渲染相关的DOM元素。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In this example, the table row (`
`) element repeats for each movie object in the collection of movies.",
"translation": "在这个例子中,对`movies`集合中的每一个`movie`对象重复渲染了这个表格行元素(`
`)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The `*ngFor` directive in Angular is similar to the `ng-repeat` directive in AngularJS. It repeats\n the associated DOM element for each item in the specified collection.\n More accurately, it turns the defined element (`
` in this example) and its contents into a template and\n uses that template to instantiate a view for each item in the list.",
"translation": "Angular中的`*ngFor`指令类似于AngularJS中的`ng-repeat`指令。\n 它为指定集合中的每一个条目重复渲染了相关的DOM元素。\n 更准确的说,它把被界定出来的元素(这个例子中是`
`)及其内容转成了一个模板,并使用那个模板来为列表中的每一个条目实例化一个视图。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Notice the other syntax differences:\n The (*) before `ngFor` is required;\n the `let` keyword identifies `movie` as an input variable;\n the list preposition is `of`, not `in`.",
"translation": "请注意其它语法上的差异:\n 在`ngFor`前面的星号(*)是必须的;`let`关键字把`movie`标记成一个输入变量;列表中使用的介词是`of`,而不再是`in`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information, see [Structural Directives](guide/structural-directives).",
"translation": "要了解更多信息,参见[结构性指令](guide/structural-directives)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, the `ng-show` directive shows or hides the associated DOM element, based on\n an expression.",
"translation": "在AngularJS中,`ng-show`指令根据一个表达式来显示或隐藏相关的DOM元素。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In this example, the `
` element is shown if the `favoriteHero` variable is truthy.",
"translation": "在这个例子中,如果`favoriteHero`变量为真,`
`元素就会显示出来。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Bind to the `hidden` property",
"translation": "### 绑定到`hidden`属性",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Angular uses property binding; there is no built-in *show* directive.\n For hiding and showing elements, bind to the HTML `hidden` property.",
"translation": "在Angular中,并没有内置的*show*指令,可以改用属性绑定。\n 要隐藏或显示一个元素,绑定到它的`hidden`属性就可以了。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "To conditionally display an element, place the element's `hidden` property in square brackets and\n set it to a quoted template expression that evaluates to the *opposite* of *show*.",
"translation": "要想有条件的显示一个元素,就把该元素的`hidden`属性放到一个方括号里,并且把它设置为引号中的模板表达式,它的结果应该是与*显示*时*相反*的值。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In this example, the `
` element is hidden if the `favoriteHero` variable is not truthy.",
"translation": "在这个例子中,如果`favoriteHero`变量不是真值,`
`元素就会被隐藏。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information on property binding, see the [Property binding](guide/template-syntax#property-binding)\n section of the [Template Syntax](guide/template-syntax) page.",
"translation": "要了解属性绑定的更多知识,参见[模板语法](guide/template-syntax)中的[属性绑定](guide/template-syntax#property-binding)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The `ng-src` directive allows AngularJS to preprocess the `src` property so that it\n can replace the binding expression with the appropriate URL before the browser\n fetches from that URL.",
"translation": "`ng-src`指令允许AngularJS对`src`属性进行预处理,以便它能够在浏览器获取此URL之前,用一个返回适当URL的绑定表达式替换它。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Bind to the `src` property",
"translation": "### 绑定到`src`属性",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Angular uses property binding; there is no built-in *src* directive.\n Place the `src` property in square brackets and set it to a quoted template expression.",
"translation": "在Angular中,并没有一个内置的*src*指令,可以使用属性绑定。\n 把`src`属性放到方括号中,并且把它设为一个引号中的绑定表达式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information on property binding, see the [Property binding](guide/template-syntax#property-binding)\n section of the [Template Syntax](guide/template-syntax) page.",
"translation": "要了解属性绑定的更多知识,参见[模板语法](guide/template-syntax)中的[属性绑定](guide/template-syntax#property-binding)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, the `ng-style` directive sets a CSS style on an HTML element\n based on an expression. That expression is often a key-value control object with each\n key of the object defined as a CSS property, and each value defined as an expression\n that evaluates to a value appropriate for the style.",
"translation": "在AngularJS中,`ng-style`指令根据一个绑定表达式设置一个HTML元素的CSS样式。\n 该表达式通常是一个“键-值”形式的控制对象,对象的每个键都是一个CSS属性,每个值都是一个能计算为此样式的合适值的表达式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In the example, the `color` style is set to the current value of the `colorPreference` variable.",
"translation": "在这个例子中,`color`样式被设置为`colorPreference`变量的当前值。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, the `ngStyle` directive works similarly. It sets a CSS style on an HTML element based on an expression.",
"translation": "在Angular中,`ngStyle`指令的工作方式与此类似。它根据一个表达式设置HTML元素上的CSS样式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In the first example, the `color` style is set to the current value of the `colorPreference` variable.",
"translation": "在第一个例子中,`color`样式被设置成了`colorPreference`变量的当前值。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Angular also has **style binding**, which is good way to set a single style. This is shown in the second example.",
"translation": "Angular还有**样式绑定**语法,它是单独设置一个样式的好方法。它展示在第二个例子中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information on style binding, see the [Style binding](guide/template-syntax#style-binding) section of the\n [Template Syntax](guide/template-syntax) page.",
"translation": "要了解样式绑定的更多知识,参见[模板语法](guide/template-syntax)中的[样式绑定](guide/template-syntax#style-binding)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information on the `ngStyle` directive, see [NgStyle](guide/template-syntax#ngStyle)\n section of the [Template Syntax](guide/template-syntax) page.",
"translation": "要了解关于`ngStyle`指令的更多知识,参见[模板语法](guide/template-syntax)中的[NgStyle](guide/template-syntax#ngStyle)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, the `ng-switch` directive swaps the contents of\n an element by selecting one of the templates based on the current value of an expression.",
"translation": "在Angular1中,`ng-switch`指令根据一个表达式的当前值把元素的内容替换成几个模板之一。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In this example, if `favoriteHero` is not set, the template displays \"Please enter ...\".\n If `favoriteHero` is set, it checks the movie hero by calling a controller method.\n If that method returns `true`, the template displays \"Excellent choice!\".\n If that methods returns `false`, the template displays \"No movie, sorry!\".",
"translation": "在这个例子中,如果`favoriteHero`没有设置,则模板显示“Please enter ...”。\n 如果`favoriteHero`设置过,它就会通过调用一个控制其方法来检查它是否电影里的英雄。\n 如果该方法返回`true`,模板就会显示“Excellent choice!”。\n 如果该方法返回`false`,该模板就会显示“No movie, sorry!”。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, the `ngSwitch` directive works similarly.\n It displays an element whose `*ngSwitchCase` matches the current `ngSwitch` expression value.",
"translation": "在Angular中,`ngSwitch`指令的工作方式与此类似。\n 它会显示那个与`ngSwitch`表达式的当前值匹配的那个`*ngSwitchCase`所在的元素。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In this example, if `favoriteHero` is not set, the `ngSwitch` value is `null`\n and `*ngSwitchDefault` displays, \"Please enter ...\".\n If `favoriteHero` is set, the app checks the movie hero by calling a component method.\n If that method returns `true`, the app selects `*ngSwitchCase=\"true\"` and displays: \"Excellent choice!\"\n If that methods returns `false`, the app selects `*ngSwitchCase=\"false\"` and displays: \"No movie, sorry!\"",
"translation": "在这个例子中,如果`favoriteHero`没有设置,则`ngSwitch`的值是`null`,我们会看到\n `*ngSwitchDefault`中的段落“Please enter ...”。\n 如果`favoriteHero`被设置了,它就会通过调用一个组件方法来检查电影英雄。\n 如果该方法返回`true`,我们就会看到“Excellent choice!”。\n 如果该方法返回`false`,我们就会看到“No movie, sorry!”。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The (*) before `ngSwitchCase` and `ngSwitchDefault` is required in this example.",
"translation": "在这个例子中,`ngSwitchCase`和`ngSwitchDefault`前面的星号(*)是必须的。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information, see [The NgSwitch directives](guide/template-syntax#ngSwitch)\n section of the [Template Syntax](guide/template-syntax) page.",
"translation": "要了解更多信息,参见[模板语法](guide/template-syntax)中的[NgSwitch指令](guide/template-syntax#ngSwitch)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "## Filters/pipes",
"translation": "## 过滤器/管道",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Angular **pipes** provide formatting and transformation for data in the template, similar to AngularJS **filters**.\nMany of the built-in filters in AngularJS have corresponding pipes in Angular.\nFor more information on pipes, see [Pipes](guide/pipes).",
"translation": "Angular中的**管道**为模板提供了格式化和数据转换功能,类似于AngularJS中的**过滤器**。\nAngularJS中的很多内置过滤器在Angular中都有对应的管道。\n要了解管道的更多信息,参见[Pipes](guide/pipes)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Formats a number as currency.",
"translation": "把一个数字格式化成货币。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The Angular `currency` pipe is similar although some of the parameters have changed.",
"translation": "Angular的`currency`管道和1中很相似,只是有些参数变化了。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Formats a date to a string based on the requested format.",
"translation": "基于要求的格式把日期格式化成字符串。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The Angular `date` pipe is similar.",
"translation": "Angular的`date`管道和它很相似。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Selects a subset of items from the defined collection, based on the filter criteria.",
"translation": "基于过滤条件从指定的集合中选取出一个子集。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### none",
"translation": "### 没了",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For performance reasons, no comparable pipe exists in Angular. Do all your filtering in the component. If you need the same filtering code in several templates, consider building a custom pipe.",
"translation": "在Angular中,出于性能的考虑,并没有一个类似的管道。\n 过滤逻辑应该在组件中用代码实现。\n 如果它将被复用在几个模板中,可以考虑构建一个自定义管道。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Converts a JavaScript object into a JSON string. This is useful for debugging.",
"translation": "把一个JavaScript对象转换成一个JSON字符串。这对调试很有用。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The Angular `json` pipe does the same thing.",
"translation": "Angular的`json`管道做完全相同的事。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Selects up to the first parameter (2) number of items from the collection\n starting (optionally) at the beginning index (0).",
"translation": "从集合中选择从(第二参数指定的)起始索引号(0)开始的最多(第一参数指定的)条目数(2)个条目。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The `SlicePipe` does the same thing but the *order of the parameters is reversed*, in keeping\n with the JavaScript `Slice` method.\n The first parameter is the starting index; the second is the limit.\n As in AngularJS, coding this operation within the component instead could improve performance.",
"translation": "`SlicePipe`做同样的事,但是*两个参数的顺序是相反的*,以便于JavaScript中的`slice`方法保持一致。\n 第一个参数是起始索引号,第二个参数是限制的数量。\n 和AngularJS中一样,如果们改用组件中的代码实现此操作,性能将会提升。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Converts the string to lowercase.",
"translation": "把该字符串转成小写形式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The Angular `lowercase` pipe does the same thing.",
"translation": "Angular的`lowercase`管道和1中的功能完全相同。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Formats a number as text.",
"translation": "把数字格式化为文本。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The Angular `number` pipe is similar.\n It provides more functionality when defining\n the decimal places, as shown in the second example above.",
"translation": "Angular的`number`管道很相似。\n 但在指定小数点位置时,它提供了更多的功能,如第二个范例所示。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Angular also has a `percent` pipe, which formats a number as a local percentage\n as shown in the third example.",
"translation": "Angular还有一个`percent`管道,它把一个数组格式化为本地化的(local)百分比格式,如第三个范例所示。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Displays the collection in the order specified by the expression.\n In this example, the movie title orders the `movieList`.",
"translation": "使用表达式中所指定的方式对集合进行排序。\n 在这个例子中,`movieList`被根据movie的title排序了。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### none",
"translation": "### 没了",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For performance reasons, no comparable pipe exists in Angular.\n Instead, use component code to order or sort results. If you need the same ordering or sorting code in several templates, consider building a custom pipe.",
"translation": "在Angular中,出于性能的考虑,并没有一个类似的管道。\n 排序逻辑应该在组件中用代码实现。\n 如果它将被复用在几个模板中,可以考虑构建一个自定义管道。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "## Modules/controllers/components",
"translation": "## 模块/控制器/组件",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In both AngularJS and Angular, modules help you organize your application into cohesive blocks of functionality.",
"translation": "无论在AngularJS还是Angular中,我们都要借助“模块”来把应用拆分成一些紧密相关的功能块。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, you write the code that provides the model and the methods for the view in a **controller**.\nIn Angular, you build a **component**.",
"translation": "在AngularJS中,我们在**控制器**中写代码,来为视图提供模型和方法。\n在Angular中,我们创建**组件**。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Because much AngularJS code is in JavaScript, JavaScript code is shown in the AngularJS column.\nThe Angular code is shown using TypeScript.",
"translation": "因为很多AngularJS的代码是用JavaScript写的,所以在AngularJS列显示的是JavaScript代码,而Angular列显示的是TypeScript代码。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, an immediately invoked function expression (or IIFE) around controller code\n keeps it out of the global namespace.",
"translation": "在AngularJS中,用立即调用的函数表达式(IIFE)来包裹控制器代码可以让控制器代码不会污染全局命名空间。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### none",
"translation": "### 没了",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "This is a nonissue in Angular because ES 2015 modules\n handle the namespacing for you.",
"translation": "在Angular中我们不用担心这个问题,因为使用ES 2015的模块,模块会替我们处理命名空间问题。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information on modules, see the [Modules](guide/architecture#modules) section of the\n [Architecture Overview](guide/architecture).",
"translation": "要了解关于模块的更多信息,参见[架构概览](guide/architecture)中的[模块](guide/architecture#modules)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Angular modules",
"translation": "### Angular模块",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, an Angular module keeps track of controllers, services, and other code.\n The second argument defines the list of other modules that this module depends upon.",
"translation": "在AngularJS中,Angular模块用来对控制器、服务和其它代码进行跟踪。第二个参数定义该模块依赖的其它模块列表。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "NgModules, defined with the `NgModule` decorator, serve the same purpose:",
"translation": "Angular的模块用`NgModule`装饰器进行定义,有如下用途:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "* `imports`: specifies the list of other modules that this module depends upon",
"translation": "`imports`: 指定当前模块依赖的其它模块列表",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "* `declaration`: keeps track of your components, pipes, and directives.",
"translation": "`declaration`: 用于记录组件、管道和指令。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information on modules, see [NgModules](guide/ngmodules).",
"translation": "要了解关于模块的更多知识,参见[NgModules](guide/ngmodules)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Controller registration",
"translation": "### 控制器注册",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "AngularJS has code in each controller that looks up an appropriate Angular module\n and registers the controller with that module.",
"translation": "在AngularJS中,在每个控制器中都有一些代码,用于找到合适的Angular模块并把该控制器注册进去。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "The first argument is the controller name. The second argument defines the string names of\n all dependencies injected into this controller, and a reference to the controller function.",
"translation": "第一个参数是控制器的名称,第二个参数定义了所有将注入到该控制器的依赖的字符串名称,以及一个到控制器函数的引用。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Component decorator",
"translation": "### 组件装饰器",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Angular adds a decorator to the component class to provide any required metadata.\n The `@Component` decorator declares that the class is a component and provides metadata about\n that component such as its selector (or tag) and its template.",
"translation": "在Angular中,我们往组件类上添加了一个装饰器,以提供任何需要的元数据。\n `@Component`装饰器把该类声明为组件,并提供了关于该组件的元数据,比如它的选择器(或标签)和模板。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "This is how you associate a template with logic, which is defined in the component class.",
"translation": "这就是把模板关联到代码的方式,它定义在组件类中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information, see the [Components](guide/architecture#components)\n section of the [Architecture Overview](guide/architecture) page.",
"translation": "要了解关于组件的更多信息,参见[架构概览](guide/architecture)中的[组件](guide/architecture#components)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Controller function",
"translation": "### 控制器函数",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, you write the code for the model and methods in a controller function.",
"translation": "在Angular1中,我们在控制器函数中写模型和方法的代码。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Component class",
"translation": "### 组件类",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, you create a component class.",
"translation": "在Angular中,我们写组件类。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "NOTE: If you are using TypeScript with AngularJS, you must use the `export` keyword to export the component class.",
"translation": "注意:如果你正在用TypeScript写AngularJS,那么必须用`export`关键字来导出组件类。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information, see the [Components](guide/architecture#components)\n section of the [Architecture Overview](guide/architecture) page.",
"translation": "要了解关于组件的更多信息,参见[架构概览](guide/architecture)中的[组件](guide/architecture#components)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Dependency injection",
"translation": "### 依赖注入",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, you pass in any dependencies as controller function arguments.\n This example injects a `MovieService`.",
"translation": "在AngularJS中,我们把所有依赖都作为控制器函数的参数。\n 在这个例子中,我们注入了一个`MovieService`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "To guard against minification problems, tell Angular explicitly\n that it should inject an instance of the `MovieService` in the first parameter.",
"translation": "我们还通过在第一个参数明确告诉Angular它应该注入一个`MovieService`的实例,以防止在最小化时出现问题。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Dependency injection",
"translation": "### 依赖注入",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, you pass in dependencies as arguments to the component class constructor.\n This example injects a `MovieService`.\n The first parameter's TypeScript type tells Angular what to inject, even after minification.",
"translation": "在Angular中,我们把依赖作为组件构造函数的参数传入。\n 在这个例子中,我们注入了一个`MovieService`。\n 即使在最小化之后,第一个参数的TypeScript类型也会告诉Angular它该注入什么。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "For more information, see the [Dependency injection](guide/architecture#dependency-injection)\n section of the [Architecture Overview](guide/architecture).",
"translation": "要了解关于依赖注入的更多信息,参见[架构概览](guide/architecture)中的[依赖注入](guide/architecture#dependency-injection)部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "## Style sheets",
"translation": "## 样式表",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "Style sheets give your application a nice look.\nIn AngularJS, you specify the style sheets for your entire application.\nAs the application grows over time, the styles for the many parts of the application\nmerge, which can cause unexpected results.\nIn Angular, you can still define style sheets for your entire application. But now you can\nalso encapsulate a style sheet within a specific component.",
"translation": "样式表美化我们的应用程序。\n在AngularJS中,我们为整个应用程序指定样式表。\n当应用程序成长一段时间之后,应用程序中很多部分的样式会被合并,导致无法预计的后果。\n在Angular中,我们仍然会为整个应用程序定义样式,不过现在也可以把样式表封装在特定的组件中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Link tag",
"translation": "### Link标签",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "AngularJS, uses a `link` tag in the head section of the `index.html` file\n to define the styles for the application.",
"translation": "在AngularJS中,我们在`index.html`的`head`区使用`link`标签来为应用程序定义样式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "### Styles configuration",
"translation": "### 样式配置",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "With the Angular CLI, you can configure your global styles in the `.angular-cli.json` file.\n You can rename the extension to `.scss` to use sass.",
"translation": "使用 Angular CLI,我们可以在 `.angular-cli.json` 文件中配置全局样式。\n 也可以把扩展名改为 `.scss` 来使用 sass。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, you can use the `styles` or `styleUrls` property of the `@Component` metadata to define\n a style sheet for a particular component.",
"translation": "在Angular中,我们可以在`@Component`的元数据中使用`styles`或`styleUrls`属性来为一个特定的组件定义样式表。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "This allows you to set appropriate styles for individual components that won’t leak into\n other parts of the application.",
"translation": "这让我们可以为各个组件设置合适的样式,而不用担心它被泄漏到程序中的其它部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/ajs-quick-reference.md"
},
{
"original": "# Animations",
"translation": "# 动画",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Motion is an important aspect in the design of modern web applications. Good\nuser interfaces transition smoothly between states with engaging animations\nthat call attention where it's needed. Well-designed animations can make a UI not only\nmore fun but also easier to use.",
"translation": "动画是现代Web应用设计中一个很重要的方面。我们希望用户界面能在不同的状态之间更平滑的转场。如果需要,还可以用适当的动画来吸引注意力。\n设计良好的动画不但会让UI更有趣,还会让它更容易使用。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "## Overview",
"translation": "## 概览",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Angular's animation system lets you build animations that run with the same kind of native\nperformance found in pure CSS animations. You can also tightly integrate your\nanimation logic with the rest of your application code, for ease of control.",
"translation": "Angular的动画系统赋予了制作各种动画效果的能力,以构建出与原生CSS动画性能相同的动画。\n我们也获得了额外的让动画逻辑与其它应用代码紧紧集成在一起的能力,这让动画可以被更容易的触发与控制。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Angular animations are built on top of the standard [Web Animations API](https://w3c.github.io/web-animations/)\nand run natively on [browsers that support it](http://caniuse.com/#feat=web-animation).",
"translation": "Angular动画是基于标准的[Web动画API(Web Animations API)](https://w3c.github.io/web-animations/)构建的,它们在[支持此API的浏览器中](http://caniuse.com/#feat=web-animation)会用原生方式工作。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "As of Angular 6, If the Web Animations API is not supported natively by the browser, then Angular will use CSS\nkeyframes as a fallback instead (automatically). This means that the polyfill is no longer required unless any\ncode uses [AnimationBuilder](/api/animations/AnimationBuilder). If your code does use AnimationBuilder, then\nuncomment the `web-animations-js` polyfill from the `polyfills.ts` file generated by Angular CLI.",
"translation": "对于 Angular 6,如果浏览器没有提供对 Web 动画 API 的原生支持,Angular 就会自动改用 CSS 的关键帧动画作为后备实现。这意味,除非要在代码中使用 [AnimationBuilder](/api/animations/AnimationBuilder) ,否则不必使用相关的腻子脚本。\n如果你要在代码中使用 AnimationBuilder ,就要从 Angular CLI 自动生成的 `polyfills.ts` 文件中反注释掉 `web-animations-js` 腻子脚本。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "The examples in this page are available as a .",
"translation": "本章中引用的这个例子可以到去体验。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "## Setup",
"translation": "## 准备工作",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Before you can add animations to your application, you need\nto import a few animation-specific modules and functions to the root application module.",
"translation": "在往应用中添加动画之前,你要首先在应用的根模块中引入一些与动画有关的模块和函数。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "#### Example basics",
"translation": "#### 基本例子",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "The animations examples in this guide animate a list of heroes.",
"translation": "这里的动画例子用来给英雄列表添加动画。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "A `Hero` class has a `name` property, a `state` property that indicates if the hero is active or not,\nand a `toggleState()` method to switch between the states.",
"translation": "`Hero` 类有一个 `name` 属性、一个 `state` 属性(用于表明该英雄是否为激活状态)和一个 `toggleState()` 函数,用来在这两种状态之间切换。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Across the top of the screen (`app.hero-team-builder.component.ts`)\nare a series of buttons that add and remove heroes from the list (via the `HeroService`). \nThe buttons trigger changes to the list that all of the example components see at the same time.",
"translation": "在屏幕的顶部(`app.hero-team-builder.component.ts`)是一系列按钮,用于从列表中添加和删除英雄(通过 `HeroService`)。\n这些按钮会引起列表的变化,同时可以看到列表中的所有范例组件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "## Transitioning between two states",
"translation": "## 快速起步范例:在两个状态间转场",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "You can build a simple animation that transitions an element between two states\ndriven by a model attribute.",
"translation": "我们来构建一个简单的动画,它会让一个元素用模型驱动的方式在两个状态之间转场。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Animations can be defined inside `@Component` metadata.",
"translation": "动画会被定义在`@Component`元数据中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "With these, you can define an *animation trigger* called `heroState` in the component\nmetadata. It uses animations to transition between two states: `active` and `inactive`. When a\nhero is active, the element appears in a slightly larger size and lighter color.",
"translation": "通过这些,可以在组件元数据中定义一个名叫`heroState`的*动画触发器*。它在两个状态`active`和`inactive`之间进行转场。\n当英雄处于激活状态时,它会把该元素显示得稍微大一点、亮一点。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "In this example, you are defining animation styles (color and transform) inline in the\nanimation metadata.",
"translation": "在这个例子中,我们在元数据中用内联的方式定义了动画样式(`color`和`transform`)。在即将到来的一个Angular版本中,还将支持从组件的CSS样式表中提取样式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Now, using the `[@triggerName]` syntax, attach the animation that you just defined to\none or more elements in the component's template.",
"translation": "我们刚刚定义了一个动画,但它还没有被用到任何地方。要想使用它,可以在模板中用`[@triggerName]`语法来把它附加到一个或多个元素上。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Here, the animation trigger applies to every element repeated by an `ngFor`. Each of\nthe repeated elements animates independently. The value of the\nattribute is bound to the expression `hero.state` and is always either `active` or `inactive`.",
"translation": "这里,我们把该动画触发器添加到了由`ngFor`重复出来的每一个元素上。每个重复出来的元素都有独立的动画效果。\n然后把`@triggerName`属性(Attribute)的值设置成表达式`hero.state`。这个值应该或者是`inactive`或者是`active`,因为我们刚刚为它们俩定义过动画状态。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "With this setup, an animated transition appears whenever a hero object changes state.\nHere's the full component implementation:",
"translation": "通过这些设置,一旦英雄对象的状态发生了变化,就会触发一个转场动画。下面是完整的组件实现:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "## States and transitions",
"translation": "## 状态与转场",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Angular animations are defined as logical **states** and **transitions**\nbetween states.",
"translation": "Angular动画是由**状态**和**状态之间的转场效果**所定义的。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "An animation state is a string value that you define in your application code. In the example\nabove, the states `'active'` and `'inactive'` are based on the logical state of\nhero objects. The source of the state can be a simple object attribute, as it was in this case,\nor it can be a value computed in a method. The important thing is that you can read it into the\ncomponent's template.",
"translation": "动画状态是一个由程序代码中定义的字符串值。在上面的例子中,基于英雄对象的逻辑状态,我们使用了`'active'`和`'inactive'`这两种状态。\n状态的来源可以是像本例中这样简单的对象属性,也可以是由方法计算出来的值。重点是,我们得能从组件模板中读取它。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "You can define *styles* for each animation state:",
"translation": "我们可以为每个动画状态定义了*一组样式*:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "These `state` definitions specify the *end styles* of each state.\nThey are applied to the element once it has transitioned to that state, and stay\n*as long as it remains in that state*. In effect, you're defining what styles the element has in different states.",
"translation": "这些`state`具体定义了每个状态的*最终样式*。一旦元素转场到那个状态,该样式就会被应用到此元素上,*当它留在此状态时*,这些样式也会一直保持着。\n从这个意义上讲,这里其实并不只是在定义动画,而是在定义该元素在不同状态时应该具有的样式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "After you define states, you can define *transitions* between the states. Each transition\ncontrols the timing of switching between one set of styles and the next:",
"translation": "定义完状态,就能定义在状态之间的各种*转场*了。每个转场都会控制一条在一组样式和下一组样式之间切换的时间线:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "If several transitions have the same timing configuration, you can combine\nthem into the same `transition` definition:",
"translation": "如果多个转场都有同样的时间线配置,就可以把它们合并进同一个`transition`定义中:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "When both directions of a transition have the same timing, as in the previous\nexample, you can use the shorthand syntax `<=>`:",
"translation": "如果要对同一个转场的两个方向都使用相同的时间线(就像前面的例子中那样),就可以使用`<=>`这种简写语法:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "You can also apply a style during an animation but not keep it around\nafter the animation finishes. You can define such styles inline, in the `transition`. In this example,\nthe element receives one set of styles immediately and is then animated to the next.\nWhen the transition finishes, none of these styles are kept because they're not\ndefined in a `state`.",
"translation": "有时希望一些样式只在动画期间生效,但在结束后并不保留它们。这时可以把这些样式内联在`transition`中进行定义。\n在这个例子中,该元素会立刻获得一组样式,然后动态转场到下一个状态。当转场结束时,这些样式并不会被保留,因为它们并没有被定义在`state`中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "### The wildcard state `*`",
"translation": "### `*`(通配符)状态",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "The `*` (\"wildcard\") state matches *any* animation state. This is useful for defining styles and\ntransitions that apply regardless of which state the animation is in. For example:",
"translation": "`*`(通配符)状态匹配*任何*动画状态。当定义那些不需要管当前处于什么状态的样式及转场时,这很有用。比如:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* The `active => *` transition applies when the element's state changes from `active` to anything else.",
"translation": "当该元素的状态从`active`变成任何其它状态时,`active => *`转场都会生效。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* The `* => *` transition applies when *any* change between two states takes place.",
"translation": "当在*任意*两个状态之间切换时,`* => *`转场都会生效。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "### The `void` state",
"translation": "### `void`状态",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "The special state called `void` can apply to any animation. It applies\nwhen the element is *not* attached to a view, perhaps because it has not yet been\nadded or because it has been removed. The `void` state is useful for defining enter and\nleave animations.",
"translation": "有一种叫做`void`的特殊状态,它可以应用在任何动画中。它表示元素*没有*被附加到视图。这种情况可能是由于它尚未被添加进来或者已经被移除了。\n`void`状态在定义“进场”和“离场”的动画时会非常有用。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "For example the `* => void` transition applies when the element leaves the view,\nregardless of what state it was in before it left.",
"translation": "比如当一个元素离开视图时,`* => void`转场就会生效,而不管它在离场以前是什么状态。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "The wildcard state `*` also matches `void`.",
"translation": "`*`通配符状态也能匹配`void`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "## Example: Entering and leaving",
"translation": "## 例子:进场与离场",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Using the `void` and `*` states you can define transitions that animate the\nentering and leaving of elements:",
"translation": "使用`void`和`*`状态,可以定义元素进场与离场时的转场动画:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* Enter: `void => *`",
"translation": "进场:`void => *`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* Leave: `* => void`",
"translation": "离场:`* => void`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "For example, in the `animations` array below there are two transitions that use\nthe `void => *` and `* => void` syntax to animate the element in and out of the view.",
"translation": "例如,在下面的`animations`数组中,这两个转场语句使用`void => *`和`* => void`语法来让该元素以动画形式进入和离开当前视图。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Note that in this case the styles are applied to the void state directly in the\ntransition definitions, and not in a separate `state(void)` definition. Thus, the transforms\nare different on enter and leave: the element enters from the left\nand leaves to the right.",
"translation": "注意,在这个例子中,这些样式在转场定义中被直接应用到了`void`状态,但并没有一个单独的`state(void)`定义。\n这么做是因为希望在进场与离场时使用不一样的转换效果:元素从左侧进场,从右侧离开。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "These two common animations have their own aliases:",
"translation": "这两个常见的动画有自己的别名:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "## Example: Entering and leaving from different states",
"translation": "## 范例:从不同的状态下进场和离场",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "You can also combine this animation with the earlier state transition animation by\nusing the hero state as the animation state. This lets you configure\ndifferent transitions for entering and leaving based on what the state of the hero\nis:",
"translation": "通过把英雄的状态用作动画的状态,还能把该动画跟以前的转场动画组合成一个复合动画。这让我们能根据该英雄的当前状态为其配置不同的进场与离场动画:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* Inactive hero enter: `void => inactive`",
"translation": "非激活英雄进场:`void => inactive`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* Active hero enter: `void => active`",
"translation": "激活英雄进场:`void => active`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* Inactive hero leave: `inactive => void`",
"translation": "非激活英雄离场:`inactive => void`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* Active hero leave: `active => void`",
"translation": "激活英雄离场:`active => void`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "This gives you fine-grained control over each transition:",
"translation": "现在就对每一种转场都有了细粒度的控制:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "## Animatable properties and units",
"translation": "## 可动的(Animatable)属性与单位",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Since Angular's animation support builds on top of Web Animations, you can animate any property\nthat the browser considers *animatable*. This includes positions, sizes, transforms, colors,\nborders, and many others. The W3C maintains\n[a list of animatable properties](https://www.w3.org/TR/css3-transitions/#animatable-properties)\non its [CSS Transitions page](https://www.w3.org/TR/css3-transitions).",
"translation": "由于Angular的动画支持是基于Web Animations标准的,所以也能支持浏览器认为可以*参与动画*的任何属性。这些属性包括位置(position)、大小(size)、变换(transform)、颜色(color)、边框(border)等很多属性。W3C维护着\n[一个“可动”属性列表](https://www.w3.org/TR/css3-transitions/#animatable-properties)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "For positional properties that have a numeric value, you can define a unit by providing\nthe value as a string with the appropriate suffix:",
"translation": "尺寸类属性(如位置、大小、边框等)包括一个数字值和一个用来定义长度单位的后缀:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "If you don't provide a unit when specifying dimension, Angular assumes the default of `px`:",
"translation": "对大多数尺寸类属性而言,还能只定义一个数字,那就表示它使用的是像素(px)数:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* `50` is the same as saying `'50px'`",
"translation": "`50`相当于`'50px'`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "## Automatic property calculation",
"translation": "## 自动属性值计算",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Sometimes you don't know the value of a dimensional style property until runtime.\nFor example, elements often have widths and heights that\ndepend on their content and the screen size. These properties are often tricky\nto animate with CSS.",
"translation": "有时候,我们想在动画中使用的尺寸类样式,它的值在开始运行之前都是不可知的。比如,元素的宽度和高度往往依赖于它们的内容和屏幕的尺寸。处理这些属性对CSS动画而言通常是相当棘手的。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "In these cases, you can use a special `*` property value so that the value of the\nproperty is computed at runtime and then plugged into the animation.",
"translation": "如果用Angular动画,就可以用一个特殊的`*`属性值来处理这种情况。该属性的值将会在运行期被计算出来,然后插入到这个动画中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "In this example, the leave animation takes whatever height the element has before it\nleaves and animates from that height to zero:",
"translation": "这个例子中的“离场”动画会取得该元素在离场前的高度,并且把它从这个高度用动画转场到0高度:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "## Animation timing",
"translation": "## 动画时间线",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "There are three timing properties you can tune for every animated transition:\nthe duration, the delay, and the easing function. They are all combined into\na single transition *timing string*.",
"translation": "对每一个动画转场效果,有三种时间线属性可以调整:持续时间(duration)、延迟(delay)和缓动(easing)函数。它们被合并到了一个单独的*转场时间线字符串*。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "### Duration",
"translation": "### 持续时间",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "The duration controls how long the animation takes to run from start to finish.\nYou can define a duration in three ways:",
"translation": "持续时间控制动画从开始到结束要花多长时间。可以用三种方式定义持续时间:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* As a plain number, in milliseconds: `100`",
"translation": "作为一个普通数字,以毫秒为单位,如:`100`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* In a string, as milliseconds: `'100ms'`",
"translation": "作为一个字符串,以毫秒为单位,如:`'100ms'`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* In a string, as seconds: `'0.1s'`",
"translation": "作为一个字符串,以秒为单位,如:`'0.1s'`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "### Delay",
"translation": "### 延迟",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "The delay controls the length of time between the animation trigger and the beginning\nof the transition. You can define one by adding it to the same string\nfollowing the duration. It also has the same format options as the duration:",
"translation": "延迟控制的是在动画已经触发但尚未真正开始转场之前要等待多久。可以把它添加到字符串中的持续时间后面,它的选项格式也跟持续时间是一样的:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* Wait for 100ms and then run for 200ms: `'0.2s 100ms'`",
"translation": "等待100毫秒,然后运行200毫秒:`'0.2s 100ms'`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "### Easing",
"translation": "### 缓动函数",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "The [easing function](http://easings.net/) controls how the animation accelerates\nand decelerates during its runtime. For example, an `ease-in` function causes\nthe animation to begin relatively slowly but pick up speed as it progresses. You\ncan control the easing by adding it as a *third* value in the string after the duration\nand the delay (or as the *second* value when there is no delay):",
"translation": "[缓动函数](http://easings.net/)用于控制动画在运行期间如何加速和减速。比如:使用`ease-in`函数意味着动画开始时相对缓慢,然后在进行中逐步加速。可以通过在这个字符串中的持续时间和延迟后面添加*第三个*值来控制使用哪个缓动函数(如果没有定义延迟就作为*第二个*值)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* Wait for 100ms and then run for 200ms, with easing: `'0.2s 100ms ease-out'`",
"translation": "等待100毫秒,然后运行200毫秒,并且带缓动:`'0.2s 100ms ease-out'`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "* Run for 200ms, with easing: `'0.2s ease-in-out'`",
"translation": "运行200毫秒,并且带缓动:`'0.2s ease-in-out'`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "### Example",
"translation": "### 例子",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Here are a couple of custom timings in action. Both enter and leave last for\n200 milliseconds, that is `0.2s`, but they have different easings. The leave begins after a\nslight delay of 10 milliseconds as specified in `'0.2s 10 ease-out'`:",
"translation": "这里是两个自定义时间线的动态演示。“进场”和“离场”都持续200毫秒,也就是`0.2s`,但它们有不同的缓动函数。“离场”动画会在100毫秒的延迟之后开始,也就是`'0.2s 10 ease-out'`:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "## Multi-step animations with keyframes",
"translation": "## 基于关键帧(Keyframes)的多阶段动画",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Animation *keyframes* go beyond a simple transition to a more intricate animation\nthat goes through one or more intermediate styles when transitioning between two sets of styles.",
"translation": "通过定义动画的*关键帧*,可以把两组样式之间的简单转场,升级成一种更复杂的动画,它会在转场期间经历一个或多个中间样式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "For each keyframe, you specify an *offset* that defines at which point\nin the animation that keyframe applies. The offset is a number between zero,\nwhich marks the beginning of the animation, and one, which marks the end.",
"translation": "每个关键帧都可以被指定一个*偏移量*,用来定义该关键帧将被用在动画期间的哪个时间点。偏移量是一个介于0(表示动画起点)和1(表示动画终点)之间的数组。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "This example adds some \"bounce\" to the enter and leave animations with\nkeyframes:",
"translation": "在这个例子中,我们使用关键帧来为进场和离场动画添加一些“反弹效果”:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Note that the offsets are *not* defined in terms of absolute time. They are relative\nmeasures from zero to one. The final timeline of the animation is based on the combination\nof keyframe offsets, duration, delay, and easing.",
"translation": "注意,这个偏移量并*不是*用绝对数字定义的时间段,而是在0到1之间的相对值(百分比)。动画的最终时间线会基于关键帧的偏移量、持续时间、延迟和缓动函数计算出来。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Defining offsets for keyframes is optional. If you omit them, offsets with even\nspacing are automatically assigned. For example, three keyframes without predefined\noffsets receive offsets `0`, `0.5`, and `1`.",
"translation": "为关键帧定义偏移量是可选的。如果省略它们,偏移量会自动根据帧数平均分布出来。例如,三个未定义过偏移量的关键帧会分别获得偏移量:`0`、`0.5`和`1`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "## Parallel animation groups",
"translation": "## 并行动画组(Group)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "You've seen how to animate multiple style properties at the same time:\njust put all of them into the same `style()` definition.",
"translation": "我们已经知道该如何在同一时间段进行多个样式的动画了:只要把它们都放进同一个`style()`定义中就行了!",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "But you may also want to configure different *timings* for animations that happen\nin parallel. For example, you may want to animate two CSS properties but use a\ndifferent easing function for each one.",
"translation": "但我们也可能会希望为同时发生的几个动画配置不同的*时间线*。比如,同时对两个CSS属性做动画,但又得为它们定义不同的缓动函数。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "For this you can use animation *groups*. In this example, using groups both on\nenter and leave allows for two different timing configurations. Both\nare applied to the same element in parallel, but run independently of each other:",
"translation": "这种情况下就可以用动画*组*来解决了。在这个例子中,我们同时在进场和离场时使用了组,以便能让它们使用两种不同的时间线配置。\n它们被同时应用到同一个元素上,但又彼此独立运行:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "One group animates the element transform and width; the other group animates the opacity.",
"translation": "其中一个动画组对元素的`transform`和`width`做动画,另一个组则对`opacity`做动画。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "## Animation callbacks",
"translation": "## 动画回调",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "A callback is fired when an animation is started and also when it is done.",
"translation": "当动画开始和结束时,会触发一个回调。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "In the keyframes example, you have a `trigger` called `@flyInOut`. You can hook\nthose callbacks like this:",
"translation": "对于例子中的这个关键帧,我们有一个叫做`@flyInOut`的`trigger`。在那里我们可以挂钩到那些回调,比如:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "The callbacks receive an `AnimationEvent` that contains useful properties such as\n`fromState`, `toState` and `totalTime`.",
"translation": "这些回调接收一个`AnimationTransitionEvent`参数,它包含一些有用的属性,例如`fromState`,`toState`和`totalTime`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "Those callbacks will fire whether or not an animation is picked up.",
"translation": "无论动画是否实际执行过,那些回调都会触发。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/animations.md"
},
{
"original": "The Angular Ahead-of-Time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase _before_ the browser downloads and runs that code.",
"translation": "Angular 的“预先(AOT)编译器”会在构建期间把 Angular 应用的 HTML 和 TypeScript 代码编译成高效的 JavaScript 代码,之后浏览器就可以下载并快速运行这些代码。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "This guide explains how to build with the AOT compiler using different compiler options and how to write Angular metadata that AOT can compile.",
"translation": "本章描述了如何使用 AOT 编译器,以及如何书写能被 AOT 编译的 Angular 元数据。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "Watch compiler author Tobias Bosch explain the Angular Compiler at AngularConnect 2016.",
"translation": "观看编译器作者Tobias Bosch在AngularConnect 2016大会里,对Angular编译器的演讲。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "## Angular compilation",
"translation": "## Angular 中的编译",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "See the [CLI documentation](https://github.com/angular/angular-cli/wiki) for details, especially the [`build` topic](https://github.com/angular/angular-cli/wiki/build).",
"translation": "要了解更多,请参见[CLI 文档](https://github.com/angular/angular-cli/wiki),特别是[`build` 这个主题](https://github.com/angular/angular-cli/wiki/build)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "## Why compile with AOT?",
"translation": "## 为什么需要AOT编译?",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "*Faster rendering*",
"translation": "**渲染得更快**",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "With AOT, the browser downloads a pre-compiled version of the application.\nThe browser loads executable code so it can render the application immediately, without waiting to compile the app first.",
"translation": "使用AOT,浏览器下载预编译版本的应用程序。\n浏览器直接加载运行代码,所以它可以立即渲染该应用,而不用等应用完成首次编译。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "*Fewer asynchronous requests*",
"translation": "**需要的异步请求更少**",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "The compiler _inlines_ external HTML templates and CSS style sheets within the application JavaScript,\neliminating separate ajax requests for those source files.",
"translation": "编译器把外部HTML模板和CSS样式表内联到了该应用的JavaScript中。\n消除了用来下载那些源文件的Ajax请求。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "*Smaller Angular framework download size*",
"translation": "**需要下载的Angular框架体积更小**",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "There's no need to download the Angular compiler if the app is already compiled.\nThe compiler is roughly half of Angular itself, so omitting it dramatically reduces the application payload.",
"translation": "如果应用已经编译过了,自然不需要再下载Angular编译器了。\n该编译器差不多占了Angular自身体积的一半儿,所以,省略它可以显著减小应用的体积。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "*Detect template errors earlier*",
"translation": "**提早检测模板错误**",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "The AOT compiler detects and reports template binding errors during the build step\nbefore users can see them.",
"translation": "AOT编译器在构建过程中检测和报告模板绑定错误,避免用户遇到这些错误。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "*Better security*",
"translation": "**更安全**",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "AOT compiles HTML templates and components into JavaScript files long before they are served to the client.\nWith no templates to read and no risky client-side HTML or JavaScript evaluation,\nthere are fewer opportunities for injection attacks.",
"translation": "AOT编译远在HTML模版和组件被服务到客户端之前,将它们编译到JavaScript文件。\n没有模版可以阅读,没有高风险客户端HTML或JavaScript可利用,所以注入攻击的机会较少。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "## Angular Metadata and AOT",
"translation": "## Angular 元数据与 AOT",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "The Angular **AOT compiler** extracts and interprets **metadata** about the parts of the application that Angular is supposed to manage.",
"translation": "Angular 的 **AOT 编译器**会提取并解释应用中由 Angular 管理的各个部件的**元数据**。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "Angular metadata tells Angular how to construct instances of your application classes and interact with them at runtime.",
"translation": "Angular 的元数据会告诉 Angular 如何创建应用中类的实例以及如何在运行期间与它们交互。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "You specify the metadata with **decorators** such as `@Component()` and `@Input()`.\nYou also specify metadata implicitly in the constructor declarations of these decorated classes.",
"translation": "我们通过**装饰器**来指定元数据,比如 `@Component()` 和 `@Input()`。\n我们还可以在这些带装饰器的类的构造函数中隐式指定元数据。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "In the following example, the `@Component()` metadata object and the class constructor tell Angular how to create and display an instance of `TypicalComponent`.",
"translation": "在下列范例中,`@Component()` 元数据对象和类的构造函数会告诉 Angular 如何创建和显示 `TypicalComponent` 的实例。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "The Angular compiler extracts the metadata _once_ and generates a _factory_ for `TypicalComponent`.\nWhen it needs to create a `TypicalComponent` instance, Angular calls the factory, which produces a new visual element, bound to a new instance of the component class with its injected dependency.",
"translation": "Angular 编译器只提取**一次**元数据,并且为 `TypicalComponent` 生成一个**工厂**。\n当它需要创建 `TypicalComponent` 的实例时,Angular 调用这个工厂,工厂会生成一个新的可视元素,并且把它(及其依赖)绑定到组件类的一个新实例上。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "## Metadata restrictions",
"translation": "## 元数据的限制",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "You write metadata in a _subset_ of TypeScript that must conform to the following general constraints:",
"translation": "我们只能使用 TypeScript 的一个**子集**书写元数据,它必须满足下列限制:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "1. Limit [expression syntax](#expression-syntax) to the supported subset of JavaScript.",
"translation": "[表达式语法](#expression-syntax)只支持 JavaScript 的一个有限的子集。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "2. Only reference exported symbols after [code folding](#folding).",
"translation": "只能引用[代码收缩](#folding)后导出的符号。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "3. Only call [functions supported](#supported-functions) by the compiler.",
"translation": "只能调用编译器[支持的那些函数](#supported-functions)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "4. Decorated and data-bound class members must be public.",
"translation": "被装饰和用于数据绑定的类成员必须是公共(public)的。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "The next sections elaborate on these points.",
"translation": "我们将在下一节详细解释这些问题。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "## How AOT works",
"translation": "## AOT 工作原理",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "It helps to think of the AOT compiler as having two phases: a code analysis phase in which it simply records a representation of the source; and a code generation phase in which the compiler's `StaticReflector` handles the interpretation as well as places restrictions on what it interprets.",
"translation": "我们可以把 AOT 编译器看做两个阶段:在代码分析阶段,它只记录源代码,而在代码生成阶段,编译器的`StaticReflector`会解释这些结果,并为这些结果加上限制。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "## Phase 1: analysis",
"translation": "## 阶段1:分析",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "The TypeScript compiler does some of the analytic work of the first phase. It emits the `.d.ts` _type definition files_ with type information that the AOT compiler needs to generate application code.",
"translation": "TypeScript 编译器会做一些初步的分析工作,它会生成**类型定义文件**`.d.ts`,其中带有类型信息,Angular 编译器需要借助它们来生成代码。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "At the same time, the AOT **_collector_** analyzes the metadata recorded in the Angular decorators and outputs metadata information in **`.metadata.json`** files, one per `.d.ts` file.",
"translation": "同时,AOT **收集器(collector)** 会记录 Angular 装饰器中的元数据,并把它们输出到**`.metadata.json`**文件中,和每个`.d.ts`文件相对应。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "You can think of `.metadata.json` as a diagram of the overall structure of a decorator's metadata, represented as an [abstract syntax tree (AST)](https://en.wikipedia.org/wiki/Abstract_syntax_tree).",
"translation": "我们可以把`.metadata.json`文件看做一个包括全部装饰器的元数据的全景图,就像[抽象语法树 (AST) ](https://en.wikipedia.org/wiki/Abstract_syntax_tree)一样。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "Angular's [schema.ts](https://github.com/angular/angular/blob/master/packages/compiler-cli/src/metadata/schema.ts)\ndescribes the JSON format as a collection of TypeScript interfaces.",
"translation": "Angular 的 [schema.ts](https://github.com/angular/angular/blob/master/packages/compiler-cli/src/metadata/schema.ts) 把这个 JSON 格式表示成了一组 TypeScript 接口。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "The _collector_ only understands a subset of JavaScript.\nDefine metadata objects with the following limited syntax:",
"translation": "这个**收集器**只能理解 JavaScript 的一个子集。\n请使用下列受限语法定义元数据对象:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "If an expression uses unsupported syntax, the _collector_ writes an error node to the `.metadata.json` file. The compiler later reports the error if it needs that\npiece of metadata to generate the application code.",
"translation": "如果表达式使用了不支持的语法,**收集器**就会往`.metadata.json`文件中写入一个错误节点。稍后,如果编译器用到元数据中的这部分内容来生成应用代码,它就会报告这个错误。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "If you want `ngc` to report syntax errors immediately rather than produce a `.metadata.json` file with errors, set the `strictMetadataEmit` option in `tsconfig`.",
"translation": "如果你希望`ngc`立即汇报这些语法错误,而不要生成带有错误信息的`.metadata.json`文件,可以到`tsconfig`中设置 `strictMetadataEmit` 选项。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "Angular libraries have this option to ensure that all Angular `.metadata.json` files are clean and it is a best practice to do the same when building your own libraries.",
"translation": "Angular 库通过这个选项来确保所有的 `.metadata.json` 文件都是干净的。当你要构建自己的代码库时,这也同样是一项最佳实践。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "## Summary",
"translation": "## 小结",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/aot-compiler.md"
},
{
"original": "Property",
"translation": "属性",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/api-page-class.md"
},
{
"original": "Type",
"translation": "绑定类型",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/api-page-class.md"
},
{
"original": "Description",
"translation": "说明",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/api-page-class.md"
},
{
"original": "Type",
"translation": "绑定类型",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/api-page-class.md"
},
{
"original": "Type",
"translation": "绑定类型",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/api-page-class.md"
},
{
"original": "# Architecture Overview",
"translation": "# 架构概览",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Angular is a framework for building client applications in HTML and\neither JavaScript or a language like TypeScript that compiles to JavaScript.",
"translation": "Angular 是一个用 HTML 和 JavaScript 或者一个可以编译成 JavaScript 的语言(例如 Dart 或者 TypeScript ),来构建客户端应用的框架。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The framework consists of several libraries, some of them core and some optional.",
"translation": "该框架包括一系列库,有些是核心库,有些是可选库。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "You write Angular applications by composing HTML *templates* with Angularized markup,\nwriting *component* classes to manage those templates, adding application logic in *services*,\nand boxing components and services in *modules*.",
"translation": "我们是这样写 Angular 应用的:用 Angular 扩展语法编写 HTML *模板*,\n用*组件*类管理这些模板,用*服务*添加应用逻辑,\n用*模块*打包发布组件与服务。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Then you launch the app by *bootstrapping* the _root module_.\nAngular takes over, presenting your application content in a browser and\nresponding to user interactions according to the instructions you've provided.",
"translation": "然后,我们通过*引导*_根模块_来启动该应用。\nAngular 在浏览器中接管、展现应用的内容,并根据我们提供的操作指令响应用户的交互。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Of course, there is more to it than this.\nYou'll learn the details in the pages that follow. For now, focus on the big picture.",
"translation": "当然,这只是冰山一角。后面我们将学习更多的细节。不过,目前我们还是先关注全景图吧。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The code referenced on this page is available as a .",
"translation": "本章所引用的代码见。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "## Modules",
"translation": "## 模块",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Angular apps are modular and Angular has its own modularity system called _NgModules_.",
"translation": "Angular 应用是模块化的,并且 Angular 有自己的模块系统,它被称为 _Angular 模块_或 _NgModules_。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "NgModules are a big deal.\nThis page introduces modules; the [NgModules](guide/ngmodules) pages \nrelating to NgModules covers them in detail.",
"translation": "NgModules 很重要。这里只是简单介绍,在 [NgModules](guide/ngmodules)中会做深入讲解。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Every Angular app has at least one NgModule class, [the _root module_](guide/bootstrapping \"Bootstrapping\"),\nconventionally named `AppModule`.",
"translation": "每个 Angular 应用至少有一个模块([_根模块_](guide/bootstrapping \"引导启动\")),习惯上命名为`AppModule`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "While the _root module_ may be the only module in a small application, most apps have many more\n_feature modules_, each a cohesive block of code dedicated to an application domain,\na workflow, or a closely related set of capabilities.",
"translation": "_根模块_在一些小型应用中可能是唯一的模块,大多数应用会有很多_特性模块_,每个模块都是一个内聚的代码块专注于某个应用领域、工作流或紧密相关的功能。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "An NgModule, whether a _root_ or _feature_, is a class with an `@NgModule` decorator.",
"translation": "Angular 模块(无论是_根模块_还是_特性模块_)都是一个带有`@NgModule`装饰器的类。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Decorators are functions that modify JavaScript classes.\n Angular has many decorators that attach metadata to classes so that it knows\n what those classes mean and how they should work.\n \n Learn more about decorators on the web.",
"translation": "装饰器是用来修饰 JavaScript 类的函数。\nAngular 有很多装饰器,它们负责把元数据附加到类上,以了解那些类的设计意图以及它们应如何工作。\n关于装饰器的更多信息。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "`NgModule` is a decorator function that takes a single metadata object whose properties describe the module.\nThe most important properties are:",
"translation": "`NgModule`是一个装饰器函数,它接收一个用来描述模块属性的元数据对象。其中最重要的属性是:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* `declarations` - the _view classes_ that belong to this module.\nAngular has three kinds of view classes: [components](guide/architecture#components), [directives](guide/architecture#directives), and [pipes](guide/pipes).",
"translation": "`declarations` - 声明本模块中拥有的_视图类_。Angular 有三种视图类:[组件](guide/architecture#components)、[指令](guide/architecture#directives)和[管道](guide/pipes)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* `exports` - the subset of declarations that should be visible and usable in the component [templates](guide/architecture#templates) of other modules.",
"translation": "`exports` - declarations 的子集,可用于其它模块的组件[模板](guide/architecture#templates)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* `imports` - other modules whose exported classes are needed by component templates declared in _this_ module.",
"translation": "`imports` - _本_模块声明的组件模板需要的类所在的其它模块。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* `providers` - creators of [services](guide/architecture#services) that this module contributes to\nthe global collection of services; they become accessible in all parts of the app.",
"translation": "`providers` - [服务](guide/architecture#services)的创建者,并加入到全局服务列表中,可用于应用任何部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* `bootstrap` - the main application view, called the _root component_,\nthat hosts all other app views. Only the _root module_ should set this `bootstrap` property.",
"translation": "`bootstrap` - 指定应用的主视图(称为_根组件_),它是所有其它视图的宿主。只有_根模块_才能设置`bootstrap`属性。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Here's a simple root module:",
"translation": "下面是一个简单的根模块:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The `export` of `AppComponent` is just to show how to use the `exports` array to export a component; it isn't actually necessary in this example. A root module has no reason to _export_ anything because other components don't need to _import_ the root module.",
"translation": "`AppComponent`的`export`语句只是用于演示如何导出的,它在这个例子中并不是必须的。根模块不需要_导出_任何东西,因为其它组件不需要导入根模块。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Launch an application by _bootstrapping_ its root module.\nDuring development you're likely to bootstrap the `AppModule` in a `main.ts` file like this one.",
"translation": "我们通过_引导_根模块来启动应用。\n在开发期间,你通常在一个`main.ts`文件中引导`AppModule`,就像这样:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "### NgModules vs. JavaScript modules",
"translation": "### NgModules vs. JavaScript 模块",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The NgModule — a class decorated with `@NgModule` — is a fundamental feature of Angular.",
"translation": "NgModule(一个带`@NgModule`装饰器的类)是 Angular 的基础特性之一。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "JavaScript also has its own module system for managing collections of JavaScript objects.\nIt's completely different and unrelated to the NgModule system.",
"translation": "JavaScript 也有自己的模块系统,用来管理一组 JavaScript 对象。\n它与 Angular 的模块系统完全不同且完全无关。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "In JavaScript each _file_ is a module and all objects defined in the file belong to that module.\nThe module declares some objects to be public by marking them with the `export` key word.\nOther JavaScript modules use *import statements* to access public objects from other modules.",
"translation": "JavaScript 中,每个_文件_是一个模块,文件中定义的所有对象都从属于那个模块。\n通过`export`关键字,模块可以把它的某些对象声明为公共的。\n其它 JavaScript 模块可以使用*import 语句*来访问这些公共对象。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Learn more about the JavaScript module system on the web.",
"translation": "学习更多关于 JavaScript 模块的知识。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "These are two different and _complementary_ module systems. Use them both to write your apps.",
"translation": "这两个模块化系统是互补的,我们在写程序时都会用到。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "### Angular libraries",
"translation": "### Angular 模块库",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Angular ships as a collection of JavaScript modules. You can think of them as library modules.",
"translation": "Angular 提供了一组 JavaScript 模块。可以把它们看做库模块。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Each Angular library name begins with the `@angular` prefix.",
"translation": "每个 Angular 库的名字都带有`@angular`前缀。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "You install them with the **npm** package manager and import parts of them with JavaScript `import` statements.",
"translation": "用 **npm** 包管理工具安装它们,用 JavaScript 的`import`语句导入其中某些部件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "For example, import Angular's `Component` decorator from the `@angular/core` library like this:",
"translation": "例如,象下面这样,从`@angular/core`库中导入`Component`装饰器:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "You also import NgModules from Angular _libraries_ using JavaScript import statements:",
"translation": "还可以使用 JavaScript 的导入语句从 Angular _库_中导入 Angular _模块_:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "In the example of the simple root module above, the application module needs material from within that `BrowserModule`. To access that material, add it to the `@NgModule` metadata `imports` like this.",
"translation": "在上面那个简单的根模块的例子中,应用模块需要`BrowserModule`的某些素材。要访问这些素材,就得把它加入`@NgModule`元数据的`imports`中,就像这样:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "In this way you're using both the Angular and JavaScript module systems _together_.",
"translation": "这种情况下,你同时使用了 Angular 和 JavaScript 的模块化系统。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "It's easy to confuse the two systems because they share the common vocabulary of \"imports\" and \"exports\".\nHang in there. The confusion yields to clarity with time and experience.",
"translation": "这两个系统比较容易混淆,因为它们共享相同的词汇 “imports” 和 “exports”。不过没关系,先放一放,随着时间和经验的增长,自然就清楚了。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Learn more from the [NgModules](guide/ngmodules) page.",
"translation": "更多信息,参见 [NgModules](guide/ngmodules)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "## Components",
"translation": "## 组件",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "A _component_ controls a patch of screen called a *view*.",
"translation": "_组件_负责控制屏幕上的一小块区域,我们称之为*视图*。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "For example, the following views are controlled by components:",
"translation": "例如,下列视图都是由组件控制的:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* The app root with the navigation links.",
"translation": "带有导航链接的应用根组件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* The list of heroes.",
"translation": "英雄列表。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* The hero editor.",
"translation": "英雄编辑器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "You define a component's application logic—what it does to support the view—inside a class.\nThe class interacts with the view through an API of properties and methods.",
"translation": "我们在类中定义组件的应用逻辑,为视图提供支持。\n组件通过一些由属性和方法组成的 API 与视图交互。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "For example, this `HeroListComponent` has a `heroes` property that returns an array of heroes\nthat it acquires from a service.\n`HeroListComponent` also has a `selectHero()` method that sets a `selectedHero` property when the user clicks to choose a hero from that list.",
"translation": "例如,`HeroListComponent`有一个`heroes`属性,它返回一个英雄数组,这个数组从一个服务获得。\n`HeroListComponent`还有一个当用户从列表中点选一个英雄时设置`selectedHero`属性的`selectHero()`方法。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Angular creates, updates, and destroys components as the user moves through the application.\nYour app can take action at each moment in this lifecycle through optional [lifecycle hooks](guide/lifecycle-hooks), like `ngOnInit()` declared above.",
"translation": "当用户在这个应用中漫游时, Angular 会创建、更新和销毁组件。\n应用可以通过[生命周期钩子](guide/lifecycle-hooks)在组件生命周期的各个时间点上插入自己的操作,例如上面声明的`ngOnInit()`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "## Templates",
"translation": "## 模板",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "You define a component's view with its companion **template**. A template is a form of HTML\nthat tells Angular how to render the component.",
"translation": "我们通过组件的自带的**模板**来定义组件视图。模板以 HTML 形式存在,告诉 Angular 如何渲染组件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "A template looks like regular HTML, except for a few differences. Here is a\ntemplate for our `HeroListComponent`:",
"translation": "多数情况下,模板看起来很像标准 HTML,当然也有一点不同的地方。下面是`HeroListComponent`组件的一个模板:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Although this template uses typical HTML elements like `
` and `
`, it also has some differences. Code like `*ngFor`, `{{hero.name}}`, `(click)`, `[hero]`, and `` uses Angular's [template syntax](guide/template-syntax).",
"translation": "模板除了可以使用像`
`和`
`这样的典型的 HTML 元素,还能使用其它元素。\n例如,像`*ngFor`、`{{hero.name}}`、`(click)`、`[hero]`和``这样的代码使用了 Angular 的[模板语法](guide/template-syntax)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "In the last line of the template, the `` tag is a custom element that represents a new component, `HeroDetailComponent`.",
"translation": "在模板的最后一行,``标签就是一个用来表示新组件`HeroDetailComponent`的自定义元素。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The `HeroDetailComponent` is a *different* component than the `HeroListComponent` you've been reviewing.\nThe `HeroDetailComponent` (code not shown) presents facts about a particular hero, the\nhero that the user selects from the list presented by the `HeroListComponent`.\nThe `HeroDetailComponent` is a **child** of the `HeroListComponent`.",
"translation": "`HeroDetailComponent`跟以前见到过的`HeroListComponent`是*不同*的组件。\n`HeroDetailComponent`(代码未显示)用于展现一个特定英雄的情况,这个英雄是用户从`HeroListComponent`列表中选择的。\n`HeroDetailComponent`是`HeroListComponent`的*子组件*。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Notice how `` rests comfortably among native HTML elements. Custom components mix seamlessly with native HTML in the same layouts.",
"translation": "注意到了吗?``舒适地躺在原生 HTML 元素之间。\n自定义组件和原生 HTML 在同一布局中融合得天衣无缝。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "## Metadata",
"translation": "## 元数据",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Metadata tells Angular how to process a class.",
"translation": "元数据告诉 Angular 如何处理一个类。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "[Looking back at the code](guide/architecture#component-code) for `HeroListComponent`, you can see that it's just a class.\nThere is no evidence of a framework, no \"Angular\" in it at all.",
"translation": "[回头看看](guide/architecture#component-code)`HeroListComponent`就会明白:它只是一个类。\n一点框架的痕迹也没有,里面完全没有出现 \"Angular\" 的字样。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "In fact, `HeroListComponent` really is *just a class*. It's not a component until you *tell Angular about it*.",
"translation": "实际上,`HeroListComponent`真的*只是一个类*。直到我们*告诉 Angular* 它是一个组件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "To tell Angular that `HeroListComponent` is a component, attach **metadata** to the class.",
"translation": "要告诉 Angular `HeroListComponent`是个组件,只要把**元数据**附加到这个类。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "In TypeScript, you attach metadata by using a **decorator**.\nHere's some metadata for `HeroListComponent`:",
"translation": "在TypeScript中,我们用**装饰器 (decorator) **来附加元数据。\n下面就是`HeroListComponent`的一些元数据。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Here is the `@Component` decorator, which identifies the class\nimmediately below it as a component class.",
"translation": "这里看到`@Component`装饰器,它把紧随其后的类标记成了组件类。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The `@Component` decorator takes a required configuration object with the\ninformation Angular needs to create and present the component and its view.",
"translation": "`@Component`装饰器能接受一个配置对象, Angular 会基于这些信息创建和展示组件及其视图。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Here are a few of the most useful `@Component` configuration options:",
"translation": "`@Component`的配置项包括:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* `selector`: CSS selector that tells Angular to create and insert an instance of this component\nwhere it finds a `` tag in *parent* HTML.\nFor example, if an app's HTML contains ``, then\nAngular inserts an instance of the `HeroListComponent` view between those tags.",
"translation": "`selector`: CSS 选择器,它告诉 Angular 在*父级* HTML 中查找``标签,创建并插入该组件。\n 例如,如果应用的 HTML 包含``, Angular 就会把`HeroListComponent`的一个实例插入到这个标签中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* `templateUrl`: module-relative address of this component's HTML template, shown [above](guide/architecture#templates).",
"translation": "`templateUrl`:组件 HTML 模板的模块相对地址,[如前所示](guide/architecture#templates)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* `providers`: array of **dependency injection providers** for services that the component requires.\nThis is one way to tell Angular that the component's constructor requires a `HeroService`\nso it can get the list of heroes to display.",
"translation": "`providers` - 组件所需服务的*依赖注入提供商*数组。\n这是在告诉 Angular:该组件的构造函数需要一个`HeroService`服务,这样组件就可以从服务中获得英雄数据。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The metadata in the `@Component` tells Angular where to get the major building blocks you specify for the component.",
"translation": "`@Component`里面的元数据会告诉 Angular 从哪里获取你为组件指定的主要的构建块。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The template, metadata, and component together describe a view.",
"translation": "模板、元数据和组件共同描绘出这个视图。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Apply other metadata decorators in a similar fashion to guide Angular behavior.\n`@Injectable`, `@Input`, and `@Output` are a few of the more popular decorators.",
"translation": "其它元数据装饰器用类似的方式来指导 Angular 的行为。\n例如`@Injectable`、`@Input`和`@Output`等是一些最常用的装饰器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The architectural takeaway is that you must add metadata to your code\nso that Angular knows what to do.",
"translation": "这种架构处理方式是:你向代码中添加元数据,以便 Angular 知道该怎么做。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "## Data binding",
"translation": "## 数据绑定 (data binding)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Without a framework, you would be responsible for pushing data values into the HTML controls and turning user responses\ninto actions and value updates. Writing such push/pull logic by hand is tedious, error-prone, and a nightmare to\nread as any experienced jQuery programmer can attest.",
"translation": "如果没有框架,我们就得自己把数据值推送到 HTML 控件中,并把用户的反馈转换成动作和值更新。\n如果手工写代码来实现这些推/拉逻辑,肯定会枯燥乏味、容易出错,读起来简直是噩梦 —— 写过 jQuery 的程序员大概都对此深有体会。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Angular supports **data binding**,\na mechanism for coordinating parts of a template with parts of a component.\nAdd binding markup to the template HTML to tell Angular how to connect both sides.",
"translation": "Angular 支持**数据绑定**,一种让模板的各部分与组件的各部分相互合作的机制。\n我们往模板 HTML 中添加绑定标记,来告诉 Angular 如何把二者联系起来。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "As the diagram shows, there are four forms of data binding syntax. Each form has a direction — to the DOM, from the DOM, or in both directions.",
"translation": "如图所示,数据绑定的语法有四种形式。每种形式都有一个方向 —— 绑定到 DOM 、绑定自 DOM 以及双向绑定。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The `HeroListComponent` [example](guide/architecture#templates) template has three forms:",
"translation": "`HeroListComponent`[示例](guide/architecture#templates)模板中有三种形式:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* The `{{hero.name}}` [*interpolation*](guide/displaying-data#interpolation)\ndisplays the component's `hero.name` property value within the `
`标签中显示组件的`hero.name`属性的值。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* The `[hero]` [*property binding*](guide/template-syntax#property-binding) passes the value of `selectedHero` from\nthe parent `HeroListComponent` to the `hero` property of the child `HeroDetailComponent`.",
"translation": "`[hero]`[*属性绑定*](guide/template-syntax#property-binding)把父组件`HeroListComponent`的`selectedHero`的值传到子组件`HeroDetailComponent`的`hero`属性中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* The `(click)` [*event binding*](guide/user-input#click) calls the component's `selectHero` method when the user clicks a hero's name.",
"translation": "`(click)` [*事件绑定*](guide/user-input#click)在用户点击英雄的名字时调用组件的`selectHero`方法。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "**Two-way data binding** is an important fourth form\nthat combines property and event binding in a single notation, using the `ngModel` directive.\nHere's an example from the `HeroDetailComponent` template:",
"translation": "**双向数据绑定**是重要的第四种绑定形式,它使用`ngModel`指令组合了属性绑定和事件绑定的功能。\n下面是`HeroDetailComponent`模板的范例:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "In two-way binding, a data property value flows to the input box from the component as with property binding.\nThe user's changes also flow back to the component, resetting the property to the latest value,\nas with event binding.",
"translation": "在双向绑定中,数据属性值通过属性绑定从组件流到输入框。用户的修改通过事件绑定流回组件,把属性值设置为最新的值。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Angular processes *all* data bindings once per JavaScript event cycle,\nfrom the root of the application component tree through all child components.",
"translation": "Angular 在每个 JavaScript 事件循环中处理*所有的*数据绑定,它会从组件树的根部开始,递归处理全部子组件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Data binding plays an important role in communication between a template and its component.",
"translation": "数据绑定在模板与对应组件的交互中扮演了重要的角色。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Data binding is also important for communication between parent and child components.",
"translation": "数据绑定在父组件与子组件的通讯中也同样重要。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "## Directives",
"translation": "## 指令",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Angular templates are *dynamic*. When Angular renders them, it transforms the DOM\naccording to the instructions given by **directives**.",
"translation": "Angular 模板是*动态的*。当 Angular 渲染它们时,它会根据**指令**提供的操作对 DOM 进行转换。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "A directive is a class with a `@Directive` decorator.\nA component is a *directive-with-a-template*;\na `@Component` decorator is actually a `@Directive` decorator extended with template-oriented features.",
"translation": "组件是一个*带模板的指令*;`@Component`装饰器实际上就是一个`@Directive`装饰器,只是扩展了一些面向模板的特性。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "While **a component is technically a directive**,\n components are so distinctive and central to Angular applications that this architectural overview separates components from directives.",
"translation": "虽然**严格来说组件就是一个指令**,但是组件非常独特,并在 Angular 中位于中心地位,所以在架构概览中,我们把组件从指令中独立了出来。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Two *other* kinds of directives exist: _structural_ and _attribute_ directives.",
"translation": "还有两种*其它*类型的指令:_结构型_指令和_属性 (attribute) 型_指令。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "They tend to appear within an element tag as attributes do,\nsometimes by name but more often as the target of an assignment or a binding.",
"translation": "它们往往像属性 (attribute) 一样出现在元素标签中,\n偶尔会以名字的形式出现,但多数时候还是作为赋值目标或绑定目标出现。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "**Structural** directives alter layout by adding, removing, and replacing elements in DOM.",
"translation": "**结构型**指令通过在 DOM 中添加、移除和替换元素来修改布局。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The [example template](guide/architecture#templates) uses two built-in structural directives:",
"translation": "下面的[范例模板](guide/architecture#templates)中用到了两个内置的结构型指令:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* [`*ngFor`](guide/displaying-data#ngFor) tells Angular to stamp out one `
` per hero in the `heroes` list.",
"translation": "[`*ngFor`](guide/displaying-data#ngFor)告诉 Angular 为`heroes`列表中的每个英雄生成一个`
`标签。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* [`*ngIf`](guide/displaying-data#ngIf) includes the `HeroDetail` component only if a selected hero exists.",
"translation": "[`*ngIf`](guide/displaying-data#ngIf)表示只有在选择的英雄存在时,才会包含`HeroDetail`组件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "**Attribute** directives alter the appearance or behavior of an existing element.\nIn templates they look like regular HTML attributes, hence the name.",
"translation": "**属性型** 指令修改一个现有元素的外观或行为。\n在模板中,它们看起来就像是标准的 HTML 属性,故名。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The `ngModel` directive, which implements two-way data binding, is\nan example of an attribute directive. `ngModel` modifies the behavior of\nan existing element (typically an ``)\nby setting its display value property and responding to change events.",
"translation": "`ngModel`指令就是属性型指令的一个例子,它实现了双向数据绑定。\n`ngModel`修改现有元素(一般是``)的行为:设置其显示属性值,并响应 change 事件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Angular has a few more directives that either alter the layout structure\n(for example, [ngSwitch](guide/template-syntax#ngSwitch))\nor modify aspects of DOM elements and components\n(for example, [ngStyle](guide/template-syntax#ngStyle) and [ngClass](guide/template-syntax#ngClass)).",
"translation": "Angular 还有少量指令,它们或者修改结构布局(例如 [ngSwitch](guide/template-syntax#ngSwitch)),\n或者修改 DOM 元素和组件的各个方面(例如 [ngStyle](guide/template-syntax#ngStyle)和 [ngClass](guide/template-syntax#ngClass))。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Of course, you can also write your own directives. Components such as\n`HeroListComponent` are one kind of custom directive.",
"translation": "当然,我们也能编写自己的指令。像`HeroListComponent`这样的组件就是一种自定义指令。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "## Services",
"translation": "## 服务",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "_Service_ is a broad category encompassing any value, function, or feature that your application needs.",
"translation": "*服务*是一个广义范畴,包括:值、函数,或应用所需的特性。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Almost anything can be a service.\nA service is typically a class with a narrow, well-defined purpose. It should do something specific and do it well.",
"translation": "几乎任何东西都可以是一个服务。\n典型的服务是一个类,具有专注的、明确的用途。它应该做一件特定的事情,并把它做好。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Examples include:",
"translation": "例如:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* logging service",
"translation": "日志服务",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* data service",
"translation": "数据服务",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* message bus",
"translation": "消息总线",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* tax calculator",
"translation": "税款计算器",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* application configuration",
"translation": "应用程序配置",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "There is nothing specifically _Angular_ about services. Angular has no definition of a service.\nThere is no service base class, and no place to register a service.",
"translation": "服务没有什么特别属于 *Angular* 的特性。 Angular 对于服务也没有什么定义。\n它甚至都没有定义服务的基类,也没有地方注册一个服务。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Yet services are fundamental to any Angular application. Components are big consumers of services.",
"translation": "即便如此,服务仍然是任何 Angular 应用的基础。组件就是最大的*服务*消费者。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Here's an example of a service class that logs to the browser console:",
"translation": "下面是一个服务类的范例,用于把日志记录到浏览器的控制台:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Here's a `HeroService` that uses a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) to fetch heroes.\nThe `HeroService` depends on the `Logger` service and another `BackendService` that handles the server communication grunt work.",
"translation": "下面是`HeroService`类,用于获取英雄数据,并通过一个已解析的[承诺 (Promise)](http://exploringjs.com/es6/ch_promises.html) 返回它们。\n`HeroService`还依赖于`Logger`服务和另一个用于处理服务器通讯的`BackendService`服务。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Services are everywhere.",
"translation": "服务无处不在。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Component classes should be lean. They don't fetch data from the server,\nvalidate user input, or log directly to the console.\nThey delegate such tasks to services.",
"translation": "组件类应保持精简。组件本身不从服务器获得数据、不进行验证输入,也不直接往控制台写日志。\n它们把这些任务委托给服务。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "A component's job is to enable the user experience and nothing more. It mediates between the view (rendered by the template)\nand the application logic (which often includes some notion of a _model_).\nA good component presents properties and methods for data binding.\nIt delegates everything nontrivial to services.",
"translation": "组件的任务就是提供用户体验,仅此而已。它介于视图(由模板渲染)和应用逻辑(通常包括_模型_的某些概念)之间。\n设计良好的组件为数据绑定提供属性和方法,把其它琐事都委托给服务。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Angular doesn't *enforce* these principles.\nIt won't complain if you write a \"kitchen sink\" component with 3000 lines.",
"translation": "Angular 不会*强制要求*我们遵循这些原则。\n即使我们花 3000 行代码写了一个“厨房洗碗槽”组件,它也不会抱怨什么。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Angular does help you *follow* these principles by making it easy to factor your\napplication logic into services and make those services available to components through *dependency injection*.",
"translation": "Angular 帮助我们*遵循*这些原则 —— 它让我们能轻易地把应用逻辑拆分到服务,并通过*依赖注入*来在组件中使用这些服务。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "## Dependency injection",
"translation": "## 依赖注入(dependency injection)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "_Dependency injection_ is a way to supply a new instance of a class\nwith the fully-formed dependencies it requires. Most dependencies are services.\nAngular uses dependency injection to provide new components with the services they need.",
"translation": "“依赖注入”是提供类的新实例的一种方式,还负责处理好类所需的全部依赖。大多数依赖都是服务。\nAngular 使用依赖注入来提供新组件以及组件所需的服务。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Angular can tell which services a component needs by looking at the types of its constructor parameters.\nFor example, the constructor of your `HeroListComponent` needs a `HeroService`:",
"translation": "Angular 通过查看构造函数的参数类型得知组件需要哪些服务。\n例如,`HeroListComponent`组件的构造函数需要一个`HeroService`服务:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "When Angular creates a component, it first asks an **injector** for\nthe services that the component requires.",
"translation": "当 Angular 创建组件时,会首先为组件所需的服务请求一个**注入器 (injector)**。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "An injector maintains a container of service instances that it has previously created.\nIf a requested service instance is not in the container, the injector makes one and adds it to the container\nbefore returning the service to Angular.\nWhen all requested services have been resolved and returned,\nAngular can call the component's constructor with those services as arguments.\nThis is *dependency injection*.",
"translation": "注入器维护了一个服务实例的容器,存放着以前创建的实例。\n如果所请求的服务实例不在容器中,注入器就会创建一个服务实例,并且添加到容器中,然后把这个服务返回给 Angular。\n当所有请求的服务都被解析完并返回时,Angular 会以这些服务为参数去调用组件的构造函数。\n这就是*依赖注入* 。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "The process of `HeroService` injection looks a bit like this:",
"translation": "`HeroService`注入的过程差不多是这样的:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "If the injector doesn't have a `HeroService`, how does it know how to make one?",
"translation": "如果注入器还没有`HeroService`,它怎么知道该如何创建一个呢?",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "In brief, you must have previously registered a **provider** of the `HeroService` with the injector.\nA provider is something that can create or return a service, typically the service class itself.",
"translation": "简单点说,我们必须先用注入器(injector)为`HeroService`注册一个**提供商(provider)**。\n提供商用来创建或返回服务,通常就是这个服务类本身(相当于`new HeroService()`)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "You can register providers in modules or in components.",
"translation": "我们可以在模块中或组件中注册提供商。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "In general, add providers to the [root module](guide/architecture#modules) so that\nthe same instance of a service is available everywhere.",
"translation": "但通常会把提供商添加到[根模块](guide/architecture#modules)上,以便在任何地方都使用服务的同一个实例。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Alternatively, register at a component level in the `providers` property of the `@Component` metadata:",
"translation": "或者,也可以在`@Component`元数据中的`providers`属性中把它注册在组件层:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Registering at a component level means you get a new instance of the\nservice with each new instance of that component.",
"translation": "把它注册在组件级表示该组件的每一个新实例都会有一个服务的新实例。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "",
"translation": "",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Points to remember about dependency injection:",
"translation": "需要记住的关于依赖注入的要点是:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* Dependency injection is wired into the Angular framework and used everywhere.",
"translation": "依赖注入渗透在整个 Angular 框架中,被到处使用。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* The *injector* is the main mechanism.",
"translation": "**注入器 (injector)** 是本机制的核心。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* An injector maintains a *container* of service instances that it created.",
"translation": "注入器负责维护一个*容器*,用于存放它创建过的服务实例。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* An injector can create a new service instance from a *provider*.",
"translation": "注入器能使用*提供商*创建一个新的服务实例。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* A *provider* is a recipe for creating a service.",
"translation": "*提供商*是一个用于创建服务的配方。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* Register *providers* with injectors.",
"translation": "把*提供商*注册到注入器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "## Wrap up",
"translation": "## 总结",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "You've learned the basics about the eight main building blocks of an Angular application:",
"translation": "我们学到的这些只是关于 Angular 应用程序的八个主要构造块的基础知识:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* [Modules](guide/architecture#modules)",
"translation": "[模块](guide/architecture#modules)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* [Components](guide/architecture#components)",
"translation": "[组件](guide/architecture#components)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* [Templates](guide/architecture#templates)",
"translation": "[模板](guide/architecture#templates)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* [Metadata](guide/architecture#metadata)",
"translation": "[元数据](guide/architecture#metadata)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* [Data binding](guide/architecture#data-binding)",
"translation": "[数据绑定](guide/architecture#data-binding)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* [Directives](guide/architecture#directives)",
"translation": "[指令](guide/architecture#directives)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* [Services](guide/architecture#services)",
"translation": "[服务](guide/architecture#services)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "* [Dependency injection](guide/architecture#dependency-injection)",
"translation": "[依赖注入](guide/architecture#dependency-injection)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "That's a foundation for everything else in an Angular application,\nand it's more than enough to get going.\nBut it doesn't include everything you need to know.",
"translation": "这是 Angular 应用程序中所有其它东西的基础,要使用 Angular,以这些作为开端就绰绰有余了。\n但它仍然没有包含我们需要知道的全部。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "Here is a brief, alphabetical list of other important Angular features and services.\nMost of them are covered in this documentation (or soon will be).",
"translation": "这里是一个简短的、按字母排序的列表,列出了其它重要的 Angular 特性和服务。\n它们大多数已经(或即将)包括在这份开发文档中:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "> [**Animations**](guide/animations): Animate component behavior\nwithout deep knowledge of animation techniques or CSS with Angular's animation library.",
"translation": "> [**动画**](guide/animations):用 Angular 的动画库让组件动起来,而不需要对动画技术或 CSS 有深入的了解。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "> **Change detection**: The change detection documentation will cover how Angular decides that a component property value has changed,\nwhen to update the screen, and how it uses **zones** to intercept asynchronous activity and run its change detection strategies.",
"translation": "> **变更检测**:变更检测文档会告诉你 Angular 是如何决定组件的属性值变化,什么时候该更新到屏幕,\n以及它是如何利用**区域 (zone)** 来拦截异步活动并执行变更检测策略。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "> **Events**: The events documentation will cover how to use components and services to raise events with mechanisms for\npublishing and subscribing to events.",
"translation": "> **事件**:事件文档会告诉你如何使用组件和服务触发支持发布和订阅的事件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "> [**Forms**](guide/forms): Support complex data entry scenarios with HTML-based validation and dirty checking.",
"translation": "> [**表单**](guide/forms):通过基于 HTML 的验证和脏检查机制支持复杂的数据输入场景。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "> [**HTTP**](guide/http): Communicate with a server to get data, save data, and invoke server-side actions with an HTTP client.",
"translation": "> [**HTTP**](guide/http):通过 HTTP 客户端,可以与服务器通讯,以获得数据、保存数据和触发服务端动作。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "> [**Lifecycle hooks**](guide/lifecycle-hooks): Tap into key moments in the lifetime of a component, from its creation to its destruction,\nby implementing the lifecycle hook interfaces.",
"translation": "> [**生命周期钩子**](guide/lifecycle-hooks):通过实现生命周期钩子接口,可以切入组件生命中的几个关键点:从创建到销毁。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "> [**Pipes**](guide/pipes): Use pipes in your templates to improve the user experience by transforming values for display. Consider this `currency` pipe expression:\n>\n> > `price | currency:'USD':true`\n>\n> It displays a price of 42.33 as `$42.33`.",
"translation": "> [**管道**](guide/pipes):在模板中使用管道转换成用于显示的值,以增强用户体验。例如,`currency`管道表达式:\n>\n> > `price | currency:'USD':true`\n>\n> 它把价格“42.33”显示为`$42.33`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "> [**Router**](guide/router): Navigate from page to page within the client\n application and never leave the browser.",
"translation": "> [**路由器**](guide/router):在应用程序客户端的页面间导航,并且不离开浏览器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "> [**Testing**](guide/testing): Run unit tests on your application parts as they interact with the Angular framework\nusing the _Angular Testing Platform_.",
"translation": "> [**测试**](guide/testing):使用 _Angular 测试平台_,在你的应用部件与 Angular 框架交互时进行单元测试。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/architecture.md"
},
{
"original": "# Attribute Directives",
"translation": "# 属性型指令",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "An **Attribute** directive changes the appearance or behavior of a DOM element.",
"translation": "**属性**型指令用于改变一个 DOM 元素的外观或行为。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Try the .",
"translation": "你可以到这里试试:。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "## Directives overview",
"translation": "## 指令概览",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "There are three kinds of directives in Angular:",
"translation": "在 Angular 中有三种类型的指令:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "1. Components—directives with a template.",
"translation": "组件 — 拥有模板的指令",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "1. Structural directives—change the DOM layout by adding and removing DOM elements.",
"translation": "结构型指令 — 通过添加和移除 DOM 元素改变 DOM 布局的指令",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "1. Attribute directives—change the appearance or behavior of an element, component, or another directive.",
"translation": "属性型指令 — 改变元素、组件或其它指令的外观和行为的指令。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "*Components* are the most common of the three directives.\nYou saw a component for the first time in the [QuickStart](guide/quickstart) guide.",
"translation": "*组件*是这三种指令中最常用的。\n你在[快速上手](guide/quickstart)例子中第一次见到组件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "*Structural Directives* change the structure of the view.\nTwo examples are [NgFor](guide/template-syntax#ngFor) and [NgIf](guide/template-syntax#ngIf).\nLearn about them in the [Structural Directives](guide/structural-directives) guide.",
"translation": "*结构型*指令修改视图的结构。例如,[NgFor](guide/template-syntax#ngFor) 和 [NgIf](guide/template-syntax#ngIf)。\n要了解更多,参见[结构型指令](guide/structural-directives) guide。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "*Attribute directives* are used as attributes of elements.\nThe built-in [NgStyle](guide/template-syntax#ngStyle) directive in the\n[Template Syntax](guide/template-syntax) guide, for example,\ncan change several element styles at the same time.",
"translation": "*属性型*指令改变一个元素的外观或行为。例如,内置的 [NgStyle](guide/template-syntax#ngStyle) 指令可以同时修改元素的多个样式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "## Build a simple attribute directive",
"translation": "## 创建一个简单的属性型指令",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "An attribute directive minimally requires building a controller class annotated with\n`@Directive`, which specifies the selector that identifies\nthe attribute.\nThe controller class implements the desired directive behavior.",
"translation": "属性型指令至少需要一个带有`@Directive`装饰器的控制器类。该装饰器指定了一个用于标识属性的选择器。\n控制器类实现了指令需要的指令行为。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "This page demonstrates building a simple _appHighlight_ attribute\ndirective to set an element's background color\nwhen the user hovers over that element. You can apply it like this:",
"translation": "本章展示了如何创建一个简单的属性型指令 _myHighlight_ ,当用户把鼠标悬停在一个元素上时,改变它的背景色。你可以这样用它:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "### Write the directive code",
"translation": "### 编写指令代码",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Create the directive class file in a terminal window with this CLI command.",
"translation": "在命令行窗口下用 CLI 命令创建指令类文件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "The CLI creates `src/app/highlight.directive.ts`, a corresponding test file (`.../spec.ts`, and _declares_ the directive class in the root `AppModule`.",
"translation": "CLI 会创建`src/app/highlight.directive.ts`及相应的测试文件(`.../spec.ts`),并且在根模块`AppModule`中声明这个指令类。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "_Directives_ must be declared in [Angular Modules](guide/ngmodules) in the same manner as _components_.",
"translation": "和**组件**一样,这些**指令**也必须在[Angular模块](guide/ngmodules)中进行声明。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "The generated `src/app/highlight.directive.ts` is as follows:",
"translation": "生成的`src/app/highlight.directive.ts`文件如下:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "The imported `Directive` symbol provides the Angular the `@Directive` decorator.",
"translation": "这里导入的`Directive`符号提供了 Angular 的 `@Directive` 装饰器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "The `@Directive` decorator's lone configuration property specifies the directive's\n[CSS attribute selector](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors), `[appHighlight]`.",
"translation": "`@Directive` 装饰器的配置属性中指定了该指令的 [CSS 属性型选择器](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors) `[appHighlight]`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "It's the brackets (`[]`) that make it an attribute selector.\nAngular locates each element in the template that has an attribute named `appHighlight` and applies the logic of this directive to that element.",
"translation": "这里的方括号(`[]`)表示它的属性型选择器。\nAngular 会在模板中定位每个名叫 `appHighlight` 的元素,并且为这些元素加上本指令的逻辑。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "The _attribute selector_ pattern explains the name of this kind of directive.",
"translation": "正因如此,这类指令被称为 **属性选择器** 。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "#### Why not \"highlight\"?",
"translation": "#### 为什么不直接叫做 \"highlight\"?",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Though *highlight* would be a more concise selector than *appHighlight* and it would work,\nthe best practice is to prefix selector names to ensure\nthey don't conflict with standard HTML attributes.\nThis also reduces the risk of colliding with third-party directive names.\nThe CLI added the `app` prefix for you.",
"translation": "尽管*highlight* 是一个比 *myHighlight* 更简洁的名字,而且它确实也能工作。\n但是最佳实践是在选择器名字前面添加前缀,以确保它们不会与标准 HTML 属性冲突。\n它同时减少了与第三方指令名字发生冲突的危险。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Make sure you do **not** prefix the `highlight` directive name with **`ng`** because\nthat prefix is reserved for Angular and using it could cause bugs that are difficult to diagnose.",
"translation": "确认你**没有**给`highlight`指令添加**`ng`**前缀。\n那个前缀属于 Angular,使用它可能导致难以诊断的 bug。例如,这个简短的前缀`my`可以帮助你区分自定义指令。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "After the `@Directive` metadata comes the directive's controller class,\ncalled `HighlightDirective`, which contains the (currently empty) logic for the directive.\nExporting `HighlightDirective` makes the directive accessible.",
"translation": "紧跟在`@Directive`元数据之后的就是该指令的控制器类,名叫`HighlightDirective`,它包含了该指令的逻辑(目前为空逻辑)。然后导出`HighlightDirective`,以便它能在别处访问到。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Now edit the generated `src/app/highlight.directive.ts` to look as follows:",
"translation": "现在,把刚才生成的`src/app/highlight.directive.ts`编辑成这样:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "The `import` statement specifies an additional `ElementRef` symbol from the Angular `core` library:",
"translation": "`import`语句还从 Angular 的 `core` 库中导入了一个 `ElementRef` 符号。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "You use the `ElementRef`in the directive's constructor\nto [inject](guide/dependency-injection) a reference to the host DOM element, \nthe element to which you applied `appHighlight`.",
"translation": "我们可以在指令的构造函数中注入`ElementRef`,来引用宿主 DOM 元素,",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "`ElementRef` grants direct access to the host DOM element\nthrough its `nativeElement` property.",
"translation": "`ElementRef` 通过其 `nativeElement` 属性给你了直接访问宿主 DOM 元素的能力。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "This first implementation sets the background color of the host element to yellow.",
"translation": "这里的第一个实现把宿主元素的背景色设置为了黄色。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "## Apply the attribute directive",
"translation": "## 使用属性型指令",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "To use the new `HighlightDirective`, add a paragraph (`
`) element to the template of the root `AppComponent` and apply the directive as an attribute.",
"translation": "运行应用,就会看到我们的指令确实高亮了段落中的文本。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Now run the application to see the `HighlightDirective` in action.",
"translation": "运行这个应用以查看`HighlightDirective`的实际效果。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "To summarize, Angular found the `appHighlight` attribute on the **host** `
` element.\nIt created an instance of the `HighlightDirective` class and\ninjected a reference to the `
` element into the directive's constructor\nwhich sets the `
` element's background style to yellow.",
"translation": "总结:Angular 在**宿主**元素`
`元素的背景设置为了黄色。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "## Respond to user-initiated events",
"translation": "## 响应用户引发的事件",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Currently, `appHighlight` simply sets an element color.\nThe directive could be more dynamic.\nIt could detect when the user mouses into or out of the element\nand respond by setting or clearing the highlight color.",
"translation": "当前,`appHighlight`只是简单的设置元素的颜色。\n这个指令应该在用户鼠标悬浮一个元素时,设置它的颜色。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Begin by adding `HostListener` to the list of imported symbols.",
"translation": "先把`HostListener`加进导入列表中,同时再添加`Input`符号,因为我们很快就要用到它。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Then add two eventhandlers that respond when the mouse enters or leaves,\neach adorned by the `HostListener` decorator.",
"translation": "然后使用`HostListener`装饰器添加两个事件处理器,它们会在鼠标进入或离开时进行响应。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "The `@HostListener` decorator lets you subscribe to events of the DOM\nelement that hosts an attribute directive, the `
` in this case.",
"translation": "`@HostListener`装饰器引用属性型指令的宿主元素,在这个例子中就是`
`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Of course you could reach into the DOM with standard JavaScript and attach event listeners manually.\nThere are at least three problems with _that_ approach:",
"translation": "当然,你可以通过标准的JavaScript方式手动给宿主 DOM 元素附加一个事件监听器。\n但这种方法至少有三个问题:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "1. You have to write the listeners correctly.",
"translation": "必须正确的书写事件监听器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "1. The code must *detach* the listener when the directive is destroyed to avoid memory leaks.",
"translation": "当指令被销毁的时候,必须*拆卸*事件监听器,否则会导致内存泄露。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "1. Talking to DOM API directly isn't a best practice.",
"translation": "必须直接和 DOM API 打交道,应该避免这样做。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "The handlers delegate to a helper method that sets the color on the host DOM element, `el`.",
"translation": "这些处理器委托了一个辅助方法来为DOM元素(`el`)设置颜色。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "The helper method, `highlight`, was extracted from the constructor.\nThe revised constructor simply declares the injected `el: ElementRef`.",
"translation": "这个辅助方法(`highlight`)被从构造函数中提取了出来。\n修改后的构造函数只负责声明要注入的元素 `el: ElementRef`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Here's the updated directive in full:",
"translation": "下面是修改后的指令代码:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Run the app and confirm that the background color appears when\nthe mouse hovers over the `p` and disappears as it moves out.",
"translation": "运行本应用并确认:当把鼠标移到`p`上的时候,背景色就出现了,而移开的时候,它消失了。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "## Pass values into the directive with an _@Input_ data binding",
"translation": "## 使用 `@Input` 数据绑定向指令传递值",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Currently the highlight color is hard-coded _within_ the directive. That's inflexible.\nIn this section, you give the developer the power to set the highlight color while applying the directive.",
"translation": "高亮的颜色目前是硬编码在指令中的,这不够灵活。\n我们应该让指令的使用者可以指定要用哪种颜色进行高亮。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Begin by adding `Input` to the list of symbols imported from `@angular/core`.",
"translation": "我们先从`@angular/core`中导入`Input`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Add a `highlightColor` property to the directive class like this:",
"translation": "然后把`highlightColor`属性添加到指令类中,就像这样:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "### Binding to an _@Input_ property",
"translation": "### 绑定到_@Input_属性",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Notice the `@Input` decorator. It adds metadata to the class that makes the directive's `highlightColor` property available for binding.",
"translation": "注意看`@Input`装饰器。它往类上添加了一些元数据,从而让该指令的`highlightColor`能用于绑定。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "It's called an *input* property because data flows from the binding expression _into_ the directive.\nWithout that input metadata, Angular rejects the binding; see [below](guide/attribute-directives#why-input \"Why add @Input?\") for more about that.",
"translation": "它之所以称为*输入*属性,是因为数据流是从绑定表达式流向指令内部的。\n如果没有这个元数据,Angular就会拒绝绑定,参见[稍后](guide/attribute-directives#why-input \"为什么要添加@Input?\")了解更多。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Try it by adding the following directive binding variations to the `AppComponent` template:",
"translation": "试试把下列指令绑定变量添加到`AppComponent`的模板中:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Add a `color` property to the `AppComponent`.",
"translation": "把`color`属性添加到`AppComponent`中:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Let it control the highlight color with a property binding.",
"translation": "让它通过属性绑定来控制高亮颜色。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "That's good, but it would be nice to _simultaneously_ apply the directive and set the color _in the same attribute_ like this.",
"translation": "很不错,但还可以更好。我们可以在应用该指令时在同一个属性中设置颜色,就像这样:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "The `[appHighlight]` attribute binding both applies the highlighting directive to the `
` element\nand sets the directive's highlight color with a property binding.\nYou're re-using the directive's attribute selector (`[appHighlight]`) to do both jobs.\nThat's a crisp, compact syntax.",
"translation": "`[appHighlight]`属性同时做了两件事:把这个高亮指令应用到了`
`元素上,并且通过属性绑定设置了该指令的高亮颜色。\n我们复用了该指令的属性选择器`[appHighlight]`来同时完成它们。\n这是清爽、简约的语法。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "You'll have to rename the directive's `highlightColor` property to `appHighlight` because that's now the color property binding name.",
"translation": "我们还要把该指令的`highlightColor`改名为`myHighlight`,因为它是颜色属性目前的绑定名。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "This is disagreeable. The word, `appHighlight`, is a terrible property name and it doesn't convey the property's intent.",
"translation": "这可不好。因为`appHighlight`是一个糟糕的属性名,而且不能反映该属性的意图。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "### Bind to an _@Input_ alias",
"translation": "### 绑定到_@Input_别名",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Fortunately you can name the directive property whatever you want _and_ **_alias it_** for binding purposes.",
"translation": "幸运的是,我们可以随意命名该指令的属性,并且**给它指定一个用于绑定的别名**。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Restore the original property name and specify the selector as the alias in the argument to `@Input`.",
"translation": "恢复原始属性名,并在`@Input`的参数中把选择器`myHighlight`指定为别名。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "_Inside_ the directive the property is known as `highlightColor`.\n_Outside_ the directive, where you bind to it, it's known as `appHighlight`.",
"translation": "在指令内部,该属性叫`highlightColor`,在外部,当我们绑定到它时,它叫`appHighlight`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "You get the best of both worlds: the property name you want and the binding syntax you want:",
"translation": "这是最好的结果:理想的内部属性名,理想的绑定语法:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Now that you're binding via the alias to the `highlightColor`, modify the `onMouseEnter()` method to use that property.\nIf someone neglects to bind to `appHighlightColor`, highlight the host element in red:",
"translation": "现在,我们绑定到了`highlightColor`属性,并修改`onMouseEnter()`方法来使用它。\n如果有人忘了绑定到`appHighlightColor`,那就用红色进行高亮。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Here's the latest version of the directive class.",
"translation": "这是最终版本的指令类。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "## Write a harness to try it",
"translation": "## 写个测试程序试验下",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "It may be difficult to imagine how this directive actually works.\nIn this section, you'll turn `AppComponent` into a harness that\nlets you pick the highlight color with a radio button and bind your color choice to the directive.",
"translation": "凭空想象该指令如何工作可不容易。\n在本节,我们将把`AppComponent`改成一个测试程序,它让你可以通过单选按钮来选取高亮颜色,并且把你选取的颜色绑定到指令中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Update app.component.html as follows:",
"translation": "把`app.component.html`修改成这样:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Revise the `AppComponent.color` so that it has no initial value.",
"translation": "修改`AppComponent.color`,让它不再有初始值。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Here are the harness and directive in action.",
"translation": "下面是测试程序和指令的动图。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "## Bind to a second property",
"translation": "## 绑定到第二个属性",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "This highlight directive has a single customizable property. In a real app, it may need more.",
"translation": "本例的指令只有一个可定制属性,真实的应用通常需要更多。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "At the moment, the default color—the color that prevails until\nthe user picks a highlight color—is hard-coded as \"red\".\nLet the template developer set the default color.",
"translation": "目前,默认颜色(它在用户选取了高亮颜色之前一直有效)被硬编码为红色。我们要让模板的开发者也可以设置默认颜色。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Add a second **input** property to `HighlightDirective` called `defaultColor`:",
"translation": "把第二个名叫`defaultColor`的**输入**属性添加到`HighlightDirective`中:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Revise the directive's `onMouseEnter` so that it first tries to highlight with the `highlightColor`,\nthen with the `defaultColor`, and falls back to \"red\" if both properties are undefined.",
"translation": "修改该指令的`onMouseEnter`,让它首先尝试使用`highlightColor`进行高亮,然后用`defaultColor`,如果它们都没有指定,那就用红色作为后备。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "How do you bind to a second property when you're already binding to the `appHighlight` attribute name?",
"translation": "当已经绑定过`appHighlight`属性时,要如何绑定到第二个属性呢?",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "As with components, you can add as many directive property bindings as you need by stringing them along in the template.\nThe developer should be able to write the following template HTML to both bind to the `AppComponent.color`\nand fall back to \"violet\" as the default color.",
"translation": "像组件一样,你也可以绑定到指令的很多属性,只要把它们依次写在模板中就行了。\n开发者可以绑定到`AppComponent.color`,并且用紫罗兰色作为默认颜色,代码如下:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Angular knows that the `defaultColor` binding belongs to the `HighlightDirective`\nbecause you made it _public_ with the `@Input` decorator.",
"translation": "Angular之所以知道`defaultColor`绑定属于`HighlightDirective`,是因为我们已经通过`@Input`装饰器把它设置成了*公共*属性。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Here's how the harness should work when you're done coding.",
"translation": "当这些代码完成时,测试程序工作时的动图如下:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "## Summary",
"translation": "## 小结",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "This page covered how to:",
"translation": "本章介绍了如何:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "* [Build an **attribute directive**](guide/attribute-directives#write-directive) that modifies the behavior of an element.",
"translation": "[构建一个**属性型指令**](guide/attribute-directives#write-directive),它用于修改一个元素的行为。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "* [Apply the directive](guide/attribute-directives#apply-directive) to an element in a template.",
"translation": "[把一个指令应用到](guide/attribute-directives#apply-directive)模板中的某个元素上。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "* [Respond to **events**](guide/attribute-directives#respond-to-user) that change the directive's behavior.",
"translation": "[响应**事件**](guide/attribute-directives#respond-to-user)以改变指令的行为。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "* [**Bind** values to the directive](guide/attribute-directives#bindings).",
"translation": "[把值**绑定**到指令中](guide/attribute-directives#bindings)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "The final source code follows:",
"translation": "最终的源码如下:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "You can also experience and download the .",
"translation": "你还可以体验和下载.",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "### Appendix: Why add _@Input_?",
"translation": "### 附录:为什么要加*@Input*?",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "In this demo, the `highlightColor` property is an ***input*** property of\nthe `HighlightDirective`. You've seen it applied without an alias:",
"translation": "在这个例子中`hightlightColor`是`HighlightDirective`的一个***输入型***属性。我们见过它没有用别名时的代码:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "You've seen it with an alias:",
"translation": "也见过用别名时的代码:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Either way, the `@Input` decorator tells Angular that this property is\n_public_ and available for binding by a parent component.\nWithout `@Input`, Angular refuses to bind to the property.",
"translation": "无论哪种方式,`@Input`装饰器都告诉Angular,该属性是*公共的*,并且能被父组件绑定。\n如果没有`@Input`,Angular就会拒绝绑定到该属性。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "You've bound template HTML to component properties before and never used `@Input`.\nWhat's different?",
"translation": "但我们以前也曾经把模板HTML绑定到组件的属性,而且从来没有用过`@Input`。\n差异何在?",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "The difference is a matter of trust.\nAngular treats a component's template as _belonging_ to the component.\nThe component and its template trust each other implicitly.\nTherefore, the component's own template may bind to _any_ property of that component,\nwith or without the `@Input` decorator.",
"translation": "差异在于信任度不同。\nAngular把组件的模板看做*从属于*该组件的。\n组件和它的模板默认会相互信任。\n这也就是意味着,组件自己的模板可以绑定到组件的*任意*属性,无论是否使用了`@Input`装饰器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "But a component or directive shouldn't blindly trust _other_ components and directives.\nThe properties of a component or directive are hidden from binding by default.\nThey are _private_ from an Angular binding perspective.\nWhen adorned with the `@Input` decorator, the property becomes _public_ from an Angular binding perspective.\nOnly then can it be bound by some other component or directive.",
"translation": "但组件或指令不应该盲目的信任其它组件或指令。\n因此组件或指令的属性默认是不能被绑定的。\n从Angular绑定机制的角度来看,它们是*私有*的,而当添加了`@Input`时,它们变成了*公共*的\n只有这样,它们才能被其它组件或属性绑定。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "You can tell if `@Input` is needed by the position of the property name in a binding.",
"translation": "你可以根据属性名在绑定中出现的位置来判定是否要加`@Input`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "* When it appears in the template expression to the ***right*** of the equals (=),\n it belongs to the template's component and does not require the `@Input` decorator.",
"translation": "当它出现在等号***右侧***的模板表达式中时,它属于模板所在的组件,不需要`@Input`装饰器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "* When it appears in **square brackets** ([ ]) to the **left** of the equals (=),\n the property belongs to some _other_ component or directive;\n that property must be adorned with the `@Input` decorator.",
"translation": "当它出现在等号**左边**的**方括号([ ])**中时,该属性属于*其它*组件或指令,它必须带有`@Input` 装饰器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "Now apply that reasoning to the following example:",
"translation": "试用此原理分析下列范例:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "* The `color` property in the expression on the right belongs to the template's component.\n The template and its component trust each other.\n The `color` property doesn't require the `@Input` decorator.",
"translation": "`color`属性位于右侧的绑定表达式中,它属于模板所在的组件。\n 该模板和组件相互信任。因此`color`不需要`@Input`装饰器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "* The `appHighlight` property on the left refers to an _aliased_ property of the `HighlightDirective`,\n not a property of the template's component. There are trust issues.\n Therefore, the directive property must carry the `@Input` decorator.",
"translation": "`appHighlight`属性位于左侧,它引用了`HighlightDirective`中一个*带别名的*属性,它不是模板所属组件的一部分,因此存在信任问题。\n所以,该属性必须带`@Input`装饰器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/attribute-directives.md"
},
{
"original": "# Bootstrapping",
"translation": "# 启动过程",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "#### Prerequisites",
"translation": "#### 前提条件",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "A basic understanding of the following:",
"translation": "对下列知识有基本的了解:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "* [JavaScript Modules vs. NgModules](guide/ngmodule-vs-jsmodule).",
"translation": "[JavaScript 模块与 NgModules](guide/ngmodule-vs-jsmodule).",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "An NgModule describes how the application parts fit together.\nEvery application has at least one Angular module, the _root_ module\nthat you bootstrap to launch the application.\nBy convention, it is usually called `AppModule`.",
"translation": "NgModule 用于描述应用的各个部分如何组织在一起。\n每个应用又至少一个 Angular 模块,*根*模块就是你用来启动此应用的模块。\n按照惯例,它通常命名为 `AppModule`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "If you use the CLI to generate an app, the default `AppModule` is as follows:",
"translation": "如果你使用 CLI 来生成一个应用,其默认的 `AppModule` 是这样的:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "After the import statements is a class with the\n**`@NgModule`** [decorator](guide/glossary#decorator '\"Decorator\" explained').",
"translation": "在 `import` 语句之后,是一个带有 **`@NgModule`** [装饰器](guide/glossary#decorator '\"Decorator\" explained')的类。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "The `@NgModule` decorator identifies `AppModule` as an `NgModule` class.\n`@NgModule` takes a metadata object that tells Angular how to compile and launch the application.",
"translation": "`@NgModule` 装饰器表明 `AppModule` 是一个 `NgModule` 类。\n`@NgModule` 获取一个元数据对象,它会告诉 Angular 如何编译和启动本应用。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "* **_declarations_**—this application's lone component.",
"translation": "**_declarations_** —— 该应用所拥有的组件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "* **_imports_**—import `BrowserModule` to have browser specific services such as DOM rendering, sanitization, and location.",
"translation": "**_imports_** —— 导入 `BrowserModule` 以获取浏览器特有的服务,比如 DOM 渲染、无害化处理和位置(location)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "* **_providers_**—the service providers.",
"translation": "**_providers_** —— 各种服务提供商。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "* **_bootstrap_**—the _root_ component that Angular creates and inserts\ninto the `index.html` host web page.",
"translation": "**_bootstrap_** —— *根*组件,Angular 创建它并插入`index.html`宿主页面。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "The default CLI application only has one component, `AppComponent`, so it\nis in both the `declarations` and the `bootstrap` arrays.",
"translation": "默认的 CLI 应用只有一个组件 `AppComponent`,所以它会同时出现在 `declarations` 和 `bootstrap` 数组中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "## The `declarations` array",
"translation": "## `declarations` 数组",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "The module's `declarations` array tells Angular which components belong to that module.\nAs you create more components, add them to `declarations`.",
"translation": "该模块的 `declarations` 数组告诉 Angular 哪些组件属于该模块。\n当你创建更多组件时,也要把它们添加到 `declarations` 中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "You must declare every component in exactly one `NgModule` class.\nIf you use a component without declaring it, Angular returns an\nerror message.",
"translation": "每个组件都应该(且只能)声明(declare)在一个 `NgModule` 类中。 如果你使用了未声明过的组件,Angular 就会报错。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "The `declarations` array only takes declarables. Declarables\nare components, [directives](guide/attribute-directives) and [pipes](guide/pipes).\nAll of a module's declarables must be in the `declarations` array.\nDeclarables must belong to exactly one module. The compiler emits\nan error if you try to declare the same class in more than one module.",
"translation": "`declarations` 数组只能接受可声明对象。可声明对象包括组件、[指令](guide/attribute-directives)和[管道](guide/pipes)。\n一个模块的所有可声明对象都必须放在 `declarations` 数组中。\n可声明对象必须只能属于一个模块,如果同一个类被声明在了多个模块中,编译器就会报错。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "These declared classes are visible within the module but invisible\nto components in a different module unless they are exported from\nthis module and the other module imports this one.",
"translation": "这些可声明的类在当前模块中是可见的,但是对其它模块中的组件是不可见的 —— 除非把它们从当前模块导出,\n并让对方模块导入本模块。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "An example of what goes into a declarations array follows:",
"translation": "下面是哪些类可以添加到 `declarations` 数组中的例子:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "A declarable can only belong to one module, so only declare it in\none `@NgModule`. When you need it elsewhere,\nimport the module that has the declarable you need in it.",
"translation": "每个可声明对象都只能属于一个模块,所以只能把它声明在一个 `@NgModule` 中。当你需要在其它模块中使用它时,就要在那里导入包含这个可声明对象的模块。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "**Only `@NgModule` references** go in the `imports` array.",
"translation": "**只有 `@NgModule`** 可以出现在 `imports` 数组中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "### Using directives with `@NgModule`",
"translation": "### 通过 `@NgModule` 使用指令",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "Use the `declarations` array for directives.\nTo use a directive, component, or pipe in a module, you must do a few things:",
"translation": "使用 `declarations` 数组声明指令。在模块中使用指令、组件或管道的步骤如下:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "1. Export it from the file where you wrote it.",
"translation": "从你编写它的文件中导出它。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "2. Import it into the appropriate module.",
"translation": "把它导入到适当的模块中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "3. Declare it in the `@NgModule` `declarations` array.",
"translation": "在 `@NgModule` 的 `declarations` 数组中声明它。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "Those three steps look like the following. In the file where you create your directive, export it.\nThe following example, named `ItemDirective` is the default directive structure that the CLI generates in its own file, `item.directive.ts`:",
"translation": "这三步的结果如下所示。在你创建指令的文件中导出它。\n下面的例子中,`item.directive.ts` 中的 `ItemDirective` 是 CLI 自动生成的默认指令结构。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "The key point here is that you have to export it so you can import it elsewhere. Next, import it\ninto the NgModule, in this example `app.module.ts`, with a JavaScript import statement:",
"translation": "重点在于你要先在这里导出它才能在别处导入它。接下来,使用 JavaScript 的 `import` 语句把它导入到 NgModule 中(这里是 `app.module.ts`)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "And in the same file, add it to the `@NgModule` `declarations` array:",
"translation": "同样在这个文件中,把它添加到 `@NgModule` 的 `declarations` 数组中:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "Now you could use your `ItemDirective` in a component. This example uses `AppModule`, but you'd do it the same way for a feature module. For more about directives, see [Attribute Directives](guide/attribute-directives) and [Structural Directives](guide/structural-directives). You'd also use the same technique for [pipes](guide/pipes) and components.",
"translation": "现在,你就可以在组件中使用 `ItemDirective` 了。这个例子中使用的是 `AppModule`,但是在特性模块中你也可以这么做。\n要进一步了解指令,参见[属性型指令](guide/attribute-directives)和[结构型指令](guide/structural-directives)。\n这些也同样适用于[管道](guide/pipes)和组件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "Remember, components, directives, and pipes belong to one module only. You only need to declare them once in your app because you share them by importing the necessary modules. This saves you time and helps keep your app lean.",
"translation": "记住:组件、指令和管道都只能属于一个模块。你在应用中也只需要声明它们一次,因为你还可以通过导入必要的模块来使用它们。这能节省你的时间,并且帮助你的应用保持精简。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "## The `imports` array",
"translation": "## `imports` 数组",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "The module's `imports` array appears exclusively in the `@NgModule` metadata object.\nIt tells Angular about other NgModules that this particular module needs to function properly.",
"translation": "模块的 `imports` 数组只会出现在 `@NgModule` 元数据对象中。\n它告诉 Angular 该模块想要正常工作,还需要哪些模块。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "This list of modules are those that export components, directives, or pipes\nthat the component templates in this module reference. In this case, the component is\n`AppComponent`, which references components, directives, or pipes in `BrowserModule`,\n`FormsModule`, or `HttpModule`.\nA component template can reference another component, directive,\nor pipe when the referenced class is declared in this module or\nthe class was imported from another module.",
"translation": "列表中的模块导出了本模块中的各个组件模板中所引用的各个组件、指令或管道。在这个例子中,当前组件是 `AppComponent`,它引用了导出自 `BrowserModule`、`FormsModule` 或 `HttpModule` 的组件、指令或管道。\n总之,组件的模板中可以引用在当前模块中声明的或从其它模块中导入的组件、指令、管道。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "You don't have any services to provide yet.\nBut you will create some before long and you may chose to provide many of them here.",
"translation": "你还没有提供任何服务,但是很快就会创建一些,而且可能也会选择在这里提供它们。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "## The `providers` array",
"translation": "## `providers` 数组",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "The providers array is where you list the services the app needs. When\nyou list services here, they are available app-wide. You can scope\nthem when using feature modules and lazy loading. For more information, see\n[Providers](guide/providers).",
"translation": "`providers` 数组中列出了该应用所需的服务。当直接把服务列在这里时,它们是全应用范围的。\n当你使用特性模块和惰性加载时,它们是范围化的。要了解更多,参见[服务提供商](guide/providers)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "## The `bootstrap` array",
"translation": "## `bootstrap` 数组",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "The application launches by bootstrapping the root `AppModule`, which is\nalso referred to as an `entryComponent`.\nAmong other things, the bootstrapping process creates the component(s) listed in the `bootstrap` array\nand inserts each one into the browser DOM.",
"translation": "应用是通过引导根模块 `AppModule` 来启动的,根模块还引用了 `entryComponent`。\n此外,引导过程还会创建 `bootstrap` 数组中列出的组件,并把它们逐个插入到浏览器的 DOM 中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "Each bootstrapped component is the base of its own tree of components.\nInserting a bootstrapped component usually triggers a cascade of\ncomponent creations that fill out that tree.",
"translation": "每个被引导的组件都是它自己的组件树的根。\n插入一个被引导的组件通常触发一系列组件的创建并形成组件树。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "While you can put more than one component tree on a host web page,\nmost applications have only one component tree and bootstrap a single root component.",
"translation": "虽然也可以在宿主页面中放多个组件,但是大多数应用只有一个组件树,并且只从一个根组件开始引导。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "This one root component is usually called `AppComponent` and is in the\nroot module's `bootstrap` array.",
"translation": "这个根组件通常叫做 `AppComponent`,并且位于根模块的 `bootstrap` 数组中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "## More about Angular Modules",
"translation": "## 关于Angular模块的更多知识",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "For more on NgModules you're likely to see frequently in apps,\nsee [Frequently Used Modules](#).",
"translation": "要进一步了解常见的 NgModules 知识,参见 [关于模块的常见问题](#)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/bootstrapping.md"
},
{
"original": "# Browser support",
"translation": "# 浏览器支持",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Angular supports most recent browsers. This includes the following specific versions:",
"translation": "Angular 支持大多数常用浏览器,包括下列版本:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Browser",
"translation": "浏览器",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Supported versions",
"translation": "支持的版本",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "latest",
"translation": "最新版",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "latest",
"translation": "最新版",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "2 most recent major versions",
"translation": "最近的两个主版本",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "2 most recent major versions",
"translation": "最近的两个主版本",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "2 most recent major versions",
"translation": "最近的两个主版本",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Angular's continuous integration process runs unit tests of the framework on all of these browsers for every pull request,\nusing SauceLabs and\nBrowserstack.",
"translation": "Angular 在持续集成过程中,对每一个提交都会使用 SauceLabs 和\nBrowserstack 在上述所有浏览器上执行单元测试。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "## Polyfills",
"translation": "## 腻子脚本 (polyfill)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Angular is built on the latest standards of the web platform.\nTargeting such a wide range of browsers is challenging because they do not support all features of modern browsers.",
"translation": "Angular 构建于 Web 平台的最新标准之上。\n要支持这么多浏览器是一个不小的挑战,因为它们不支持现代浏览器的所有特性。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "You compensate by loading polyfill scripts (\"polyfills\") for the browsers that you must support.\nThe [table below](#polyfill-libs) identifies most of the polyfills you might need.",
"translation": "我们可以通过加载腻子脚本(\"polyfills\")来为想要支持的浏览器弥补这些特性。\n[下表](#polyfill-libs) 列出了可能用到的大多数腻子脚本。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "The suggested polyfills are the ones that run full Angular applications.\nYou may need additional polyfills to support features not covered by this list.\nNote that polyfills cannot magically transform an old, slow browser into a modern, fast one.",
"translation": "这些建议的腻子脚本是运行完整 Angular 应用所需的。\n你可能还会需要另一些的腻子脚本来支持没有出现在此列表中的哪些特性。\n注意,这些腻子脚本并没有神奇的魔力来把老旧、慢速的浏览器变成现代、快速的浏览器,它只是填充了 API。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "## Enabling polyfills",
"translation": "## 启用腻子脚本",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "[Angular CLI](https://github.com/angular/angular-cli/wiki) users enable polyfills through the `src/polyfills.ts` file that\nthe CLI created with your project.",
"translation": "[Angular CLI](https://github.com/angular/angular-cli/wiki) 的用户可以通过自动创建的 `src/polyfills.ts` 文件来启用这些腻子脚本。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "This file incorporates the mandatory and many of the optional polyfills as JavaScript `import` statements.",
"translation": "这个文件把强制的和很多可选的腻子脚本组织成 JavaScript 的 `import` 语句。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "The npm packages for the _mandatory_ polyfills (such as `zone.js`) were installed automatically for you when you created your project and their corresponding `import` statements are ready to go. You probably won't touch these.",
"translation": "**强制性** 腻子脚本(如`zone.js`)的npm 包在创建项目时就已经自动安装了,相应的 `import` 语句也都加好了。我们一般不用动它们。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "But if you need an optional polyfill, you'll have to install its npm package.\nFor example, [if you need the web animations polyfill](http://caniuse.com/#feat=web-animation), you could install it with `npm`, using the following command (or the `yarn` equivalent):",
"translation": "但是如果要用一个可选的腻子脚本,就要通过 `npm` 或 `yarn` 来安装它们的 npm 包了。\n比如,[如果你需要 web 动画的腻子脚本](http://caniuse.com/#feat=web-animation),就要通过下列命令之一来安装它:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Then open the `polyfills.ts` file and un-comment the corresponding `import` statement as in the following example:",
"translation": "然后打开 `polyfills.ts` 文件,并反注释对应的 `import` 语句,就像这样:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "If you can't find the polyfill you want in `polyfills.ts`,\nadd it yourself, following the same pattern:",
"translation": "如果在 `polyfills.ts` 中找不到要使用的腻子脚本,就可以仿照下列模式自行添加它:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "1. install the npm package",
"translation": "安装 npm 包",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "1. `import` the file in `polyfills.ts`",
"translation": "在 `polyfills.ts` 中 `import` 这个文件",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Non-CLI users should follow the instructions [below](#non-cli).",
"translation": "不使用 CLI 的用户可以遵循[下列](#non-cli)步骤自行操作。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "### Mandatory polyfills",
"translation": "### 强制性腻子脚本",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "These are the polyfills required to run an Angular application on each supported browser:",
"translation": "下表中的腻子脚本是每个浏览器都要用到的:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Browsers (Desktop & Mobile)",
"translation": "浏览器(桌面和移动)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Polyfills Required",
"translation": "需要的腻子脚本",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "### Optional browser features to polyfill",
"translation": "### 可选浏览器特性的腻子脚本",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Some features of Angular may require additional polyfills.",
"translation": "有些 Angular 特性可能需要额外的腻子脚本。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "For example, the animations library relies on the standard web animation API, which is only available in Chrome and Firefox today.\n(note that the dependency of web-animations-js in Angular is only necessary if `AnimationBuilder` is used.)",
"translation": "例如,动画库依赖于标准的 web 动画 API,目前它只在 Chrome 和 Firefox 上可用。你可能需要一个腻子脚本来在其它浏览器上使用动画功能。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Here are the features which may require additional polyfills:",
"translation": "下列特性可能需要更多腻子脚本:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Feature",
"translation": "特性",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Polyfill",
"translation": "腻子脚本",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Browsers (Desktop & Mobile)",
"translation": "浏览器(桌面和移动)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "[JIT compilation](guide/aot-compiler).",
"translation": "[JIT 编译](guide/aot-compiler)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Required to reflect for metadata.",
"translation": "需要 reflect 来提供元数据。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "All current browsers. Enabled by default.\n Can remove if you always use AOT and only use Angular decorators.",
"translation": "默认对目前的所有浏览器都启用了。如果总是使用 AOT 模式,并且只使用 Angular 自带的装饰器,那么可以移除它。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "[Animations](guide/animations)\n Only if `Animation Builder` is used within the application--standard\n animation support in Angular doesn't require any polyfills (as of NG6).",
"translation": "[动画](guide/animations)\n 只有在应用中用到了 `Animation Builder` 时才需要;Angular 标准的动画支持是不需要任何腻子脚本的(截至 NG6)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "[Web Animations](guide/browser-support#web-animations)",
"translation": "[Web 动画](guide/browser-support#web-animations)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "
If AnimationBuilder is used then the polyfill will enable scrubbing\n support for IE/Edge and Safari (Chrome and Firefox support this natively).
",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "If you use the following deprecated i18n pipes:",
"translation": "如果你使用下列已废弃的i18n管道:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "All but Chrome, Firefox, Edge, IE11 and Safari 10",
"translation": "除了 Chrome、Firefox、Edge、IE11 和 Safari 10 外的所有浏览器",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "on SVG elements",
"translation": "在 SVG 元素上应用时",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "when sending and receiving binary data",
"translation": "用 [Http](guide/http) 发送和接收二进制数据时",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "### Suggested polyfills ##",
"translation": "### 建议的腻子脚本 ##",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Below are the polyfills which are used to test the framework itself. They are a good starting point for an application.",
"translation": "下表中是用来测试框架本身的腻子脚本,它们是应用程序的优质起点。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Polyfill",
"translation": "腻子脚本",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "License",
"translation": "授权方式",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Size*",
"translation": "大小*",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "Public domain",
"translation": "公共域",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "\\* Figures are for minified and gzipped code,\ncomputed with the closure compiler.",
"translation": "\\* 这里的数据都按最小化并且 gzip 压缩后的版本算,是由closure compiler计算出的。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "## Polyfills for non-CLI users",
"translation": "## 非 CLI 的用户的腻子脚本",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "If you are not using the CLI, you should add your polyfill scripts directly to the host web page (`index.html`), perhaps like this.",
"translation": "如果你不使用 CLI,就要直接把腻子脚本添加到宿主页(`index.html`)中,就像这样:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/browser-support.md"
},
{
"original": "# Change Log",
"translation": "# 变更记录",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The Angular documentation is a living document with continuous improvements.\nThis log calls attention to recent significant changes.",
"translation": "我们将持续不断的更新和改进Angular文档。本日志记录了近期最重要的变更。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## Updated to Angular 4.0. Documentation for Angular 2.x can be found at [v2.angular.io](https://v2.angular.io).",
"translation": "## 更新到 Angular 4.0 。Angular 2.x 的文档在 [v2.angular.io](https://v2.angular.io) 。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## All mention of moduleId removed. \"Component relative paths\" guide deleted (2017-03-13)",
"translation": "## 移除了所有的moduleId引用。移除了“组件相对路径” 的烹饪书。(2017-03-13)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "We added a new SystemJS plugin (systemjs-angular-loader.js) to our recommended SystemJS configuration.\nThis plugin dynamically converts \"component-relative\" paths in templateUrl and styleUrls to \"absolute paths\" for you.",
"translation": "我们往建议的SystemJS配置中新增了一个SystemJS插件 (systemjs-angular-loader.js) 。\n这个插件可以帮你把templateUrl和styleUrls中的组件相对路径动态转换为绝对路径。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "We strongly encourage you to only write component-relative paths.\nThat is the only form of URL discussed in these docs. You no longer need to write @Component({ moduleId: module.id }), nor should you.",
"translation": "我们强烈建议你只写组件相对路径。\n这也是本文档中所使用的唯一形式。你不必再写`@Component({ moduleId: module.id })`,而且也不应该再这么写。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## NEW: Downloadable examples for each guide (2017-02-28)",
"translation": "## 新增:每篇指南都增加了可下载的范例程序 (2017-02-28)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Now you can download the sample code for any guide and run it locally.\nLook for the new download links next to the \"live example\" links.",
"translation": "现在你可以为任何一篇指南下载范例程序,并且在本地运行它了。\n请在“在线例子”的链接后面查找新的下载链接。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## Template Syntax/Structural Directives: refreshed (2017-02-06)",
"translation": "## 模板语法/结构型指令:更新了 (2017-02-06)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The [_Template-Syntax_](guide/template-syntax) and [_Structural Directives_](guide/structural-directives)\nguides were significantly revised for clarity, accuracy, and current recommended practices.\nDiscusses ``.\nRevised samples are more clear and cover all topics discussed.",
"translation": "对[模板语法](guide/template-syntax) 和 [结构型指令](guide/structural-directives)这两篇指南做了大幅修改,来让它们更加清晰、准确,并符合当前的最佳实践。\n讨论了``。\n修改了例子,来让它们更清晰,并且涵盖了所有讨论到的主题。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## NEW: Samples re-structured with `src/` folder (2017-02-02)",
"translation": "## 新增:调整了范例程序的结构,移到了`src/`文件夹 (2017-02-02)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "All documentation samples have been realigned with the default folder structure of the Angular CLI.\nThat's a step along the road to basing the sample in the Angular CLI.\nBut it's also good in its own right.\nIt helps clearly separate app code from setup and configuration files.",
"translation": "所有的文档范例都已经向Angular CLI的默认文件夹结构看齐了。\n这是把范例迁移到Angular CLI过程中的一步。\n不过也不仅是为了迁移,它确实能帮我们把应用代码从环境代码和配置代码中分离出来。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "All samples now have a `src/` folder at the project root.\nThe former `app/` folder moves under `src/`.\nRead about moving your existing project to this structure in\n\nthe QuickStart repo update instructions.",
"translation": "我们已经把所有范例改成了使用项目根目录下的`src/`文件夹。\n也就是把以前的`app/`文件夹移到了`src/`文件夹下面。\n要了解如何对你的现有项目进行这种迁移,请参阅QuickStart中的迁移指南。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Notably:",
"translation": "要点:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "* `app/main.ts` moved to `src/main.ts`.",
"translation": "把`app/main.ts`移到`src/main.ts`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "* `app/` moved to `src/app/`.",
"translation": "把`app/`移到`src/app/`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "* `index.html`, `styles.css` and `tsconfig.json` moved inside `src/`.",
"translation": "把`index.html`、`styles.css`和`tsconfig.json`移到`src/`中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "* `systemjs.config.js` now imports `main.js` instead of `app`.",
"translation": "`systemjs.config.js`现在要导入`main.js`而不是`app`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "* Added `lite-server` configuration (`bs-config.json`) to serve `src/`.",
"translation": "新增了一个`lite-server`配置(`bs-config.json`)以便在`src/`下启动开发服务器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## NEW: Reactive Forms guide (2017-01-31)",
"translation": "## 新增:响应式(Reactive)表单指南 (2017-01-31)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The new [**Reactive Forms**](guide/reactive-forms) guide explains how and why to build a \"reactive form\".\n\"Reactive Forms\" are the code-based counterpart to the declarative \"Template Driven\" forms approach\nintroduced in the [Forms](guide/forms) guide.\nCheck it out before you decide how to add forms to your app.\nRemember also that you can use both techniques in the same app,\nchoosing the approach that best fits each scenario.",
"translation": "新的[**响应式表单**](guide/reactive-forms)指南解释了如何以及何时构建“响应式表单”。\n“响应式表单”是基于代码的表单构建方式,与[表单](guide/forms)中介绍的声明“模板驱动”表单的方法相对。\n在你决定如何往应用中添加表单之前,建议先读读那一章。\n同时,别忘了你可以在同一个应用中同时使用这两种技术,根据场景来选择最合适的方法。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## NEW: Deployment guide (2017-01-30)",
"translation": "## 新增:部署指南 (2017-01-30)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The new [Deployment](guide/deployment) guide describes techniques for putting your application on a server.\nIt includes important advice on optimizing for production.",
"translation": "新的[部署指南](guide/deployment)讲的是如何把应用放到服务器上。\n其中包括了为生产环境进行优化的重要建议。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## Hierarchical Dependency Injection: refreshed (2017-01-13)",
"translation": "## 多级依赖注入:更新完毕 (2017-01-13)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "[Hierarchical Dependency Injection](guide/hierarchical-dependency-injection) guide is significantly revised.\nCloses issue #3086.\nRevised samples are clearer and cover all topics discussed.",
"translation": "[多级依赖注入](guide/hierarchical-dependency-injection)做了显著修改。关闭了issue #3086。修改过的范例更加清晰,而且涵盖了讨论到的全部主题。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## Miscellaneous (2017-01-05)",
"translation": "## 杂项 (2017-01-05)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "* [Setup](guide/setup) guide:\nadded (optional) instructions on how to remove _non-essential_ files.",
"translation": "[环境搭建](guide/setup)指南:\n 添加了(可选的)步骤说明,告诉你如何移除*非核心*文件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "* No longer consolidate RxJS operator imports in `rxjs-extensions` file; each file should import what it needs.",
"translation": "不再在`rxjs-extensions`文件中统一导入RxJS的操作符,每个文件应该各自导入它自己所需的。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "* All samples prepend template/style URLs with `./` as a best practice.",
"translation": "所有范例都在模板/样式的URL之前添加`./`前缀 …… 而且你在实际开发中也应该这么做。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "* [Style Guide](guide/styleguide): copy edits and revised rules.",
"translation": "[风格指南](guide/styleguide):复制了编辑过的和修改过的规则。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## Router: more detail (2016-12-21)",
"translation": "## 路由:更详细 (2016-12-21)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Added more information to the [Router](guide/router) guide\nincluding sections named outlets, wildcard routes, and preload strategies.",
"translation": "往[路由指南](guide/router)中添加了更多信息,包括“命名出口(Outlet)”、通配符路由和预加载策略。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## HTTP: how to set default request headers (and other request options) (2016-12-14)",
"translation": "## Http:如何设置默认的请求头(以及其它配置项) (2016-12-14)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Added section on how to set default request headers (and other request options) to\nHTTP guide.",
"translation": "添加了一节“如何设置默认的请求头(以及其它配置项)”",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## Testing: added component test plunkers (2016-12-02)",
"translation": "## 测试:添加了组件测试的plunker范例 (2016-12-02)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Added two plunkers that each test _one simple component_ so you can write a component test plunker of your own: one for the QuickStart seed's `AppComponent` and another for the Testing guide's `BannerComponent`.\nLinked to these plunkers in \"Testing\" and \"Setup anatomy\" guides.",
"translation": "添加了两个plunker例子,每个都测试一个简单的组件,以便你可以自己在plunker中写组件测试:一个用于测试快速起步中的`AppComponent`,另一个用于测试“测试”章节的`BannerComponent`。\n并在“测试”和“环境设置剖析”中链接到它们。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## Internationalization: pluralization and _select_ (2016-11-30)",
"translation": "## 国际化:单复数和`select` (2016-11-30)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The [Internationalization (i18n)](guide/i18n) guide explains how to handle pluralization and\ntranslation of alternative texts with `select`.\nThe sample demonstrates these features too.",
"translation": "[国际化 (i18n)](guide/i18n)解释了如何处理单复数问题,和如何使用`select`来翻译候选内容。\n例子中也演示了这些特性。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## Testing: karma file updates (2016-11-30)",
"translation": "## 测试:更新了karma文件 (2016-11-30)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "* `karma.config` + `karma-test-shim` can handle multiple spec source paths;\nsee quickstart issue: [angular/quickstart#294](https://github.com/angular/quickstart/issues/294).",
"translation": "`karma.config` + `karma-test-shim`可以处理多个测试源文件路径了,参见[angular/quickstart#294](https://github.com/angular/quickstart/issues/294)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "* Displays Jasmine Runner output in the karma-launched browser.",
"translation": "在启动了karma的浏览器中显示Jasmine的输出。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## QuickStart Rewrite (2016-11-18)",
"translation": "## 全新《快速上手》 (2016-11-18)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The QuickStart is completely rewritten so that it actually is quick.\nIt references a minimal \"Hello Angular\" app running in Plunker.\nThe new [Setup](guide/setup) page tells you how to install a local development environment\nby downloading (or cloning) the QuickStart github repository.\nYou are no longer asked to copy-and-paste code into setup files that were not explained anyway.",
"translation": "完全重写了《快速上手》,变得更加快速。\n它使用了在 Plunker 中运行的最小化的 “Hello Angular” 应用。\n新添加的[搭建本地开发环境](guide/setup)页面解释了如何通过下载或者克隆 QuickStart github 库来安装本地开发环境。\n你将不再需要拷贝粘贴代码到一些并没有对其解释的配置文件中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## Sync with Angular v.2.2.0 (2016-11-14)",
"translation": "## 与Angular v.2.2.0同步(2016-11-14)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Docs and code samples updated and tested with Angular v.2.2.0.",
"translation": "使用Angular v.2.2.0更新和测试所有文档和代码例子。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## UPDATE: NgUpgrade Guide for the AOT friendly _upgrade/static_ module (2016-11-14)",
"translation": "## 更新:用于AoT的_upgrade/static_模块NgUpgrade指南 (2016-11-14)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The updated [NgUpgrade Guide](guide/upgrade) guide covers the\nnew AOT friendly `upgrade/static` module\nreleased in v.2.2.0, which is the recommended\nfacility for migrating from AngularJS to Angular.\nThe documentation for the version prior to v.2.2.0 has been removed.",
"translation": "更新的[NgUpgrade指南](guide/upgrade)涵盖在v.2.2.0发布的AoT`upgrade/static`模块,\n是从AngularJS升级至Angular的推荐工具。\n删除早于v.2.2.0版本的文档。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## ES6 described in \"TypeScript to JavaScript\" (2016-11-14)",
"translation": "## 在“从TypeScript到JavaScript”增加ES6的描述 (2016-11-14)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The updated TypeScript to JavaScript guide explains how to write apps in ES6/7\nby translating the common idioms in the TypeScript documentation examples\n(and elsewhere on the web) to ES6/7 and ES5.",
"translation": "更新了“从TypeScript到JavaScript”,以解释如何使用ES6/7编写应用。\n将TypeScript文档示例中(以及网站其它地方)的习惯用法翻译成ES6/7和ES5。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "This was [removed in August 2017](https://github.com/angular/angular/pull/18694) but can still be\nviewed in the [v2 documentation](https://v2.angular.io/docs/ts/latest/cookbook/ts-to-js.html).",
"translation": "本章已经 [于2017年8月移除](https://github.com/angular/angular/pull/18694),\n不过仍然可以在[第二版的文档中](https://v2.angular.io/docs/ts/latest/cookbook/ts-to-js.html)看到。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## Sync with Angular v.2.1.1 (2016-10-21)",
"translation": "## 与Angular v.2.1.1 同步(2016-10-21)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Docs and code samples updated and tested with Angular v.2.1.1.",
"translation": "使用Angular v.2.1.1更新和测试所有文档和代码例子。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## npm _@types_ packages replace _typings_ (2016-10-20)",
"translation": "## 使用npm的_@types_包替换_typings_ (2016-10-20)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Documentation samples now get TypeScript type information for 3rd party libraries\nfrom npm `@types` packages rather than with the _typings_ tooling.\nThe `typings.json` file is gone.",
"translation": "文档例子现在从npm的`@types`第三方库获取TypeScript类型信息,不再使用_typings_。\n删除`typings.json`文件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The [AngularJS Upgrade](guide/upgrade) guide reflects this change.\nThe `package.json` installs `@types/angular` and several `@types/angular-...`\npackages in support of upgrade; these are not needed for pure Angular development.",
"translation": "\"[从AngularJS升级](guide/upgrade)\"指南反映了这个变化。\n`package.json`安装`@types/angular`和一些`@types/angular-...`包来支持升级。它们在纯Angular开发中是不需要的。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## \"Template Syntax\" explains two-way data binding syntax (2016-10-20)",
"translation": "## \"模板语法\"添加了双向数据绑定语法的解释(2016-10-20)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Demonstrates how to two-way data bind to a custom Angular component and\nre-explains `[(ngModel)]` in terms of the basic `[()]` syntax.",
"translation": "展示了如何在自定义Angular组件中双向数据绑定,用基础`[()]`重新解释`[(ngModel)]`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## BREAKING CHANGE: `in-memory-web-api` (v.0.1.11) delivered as esm umd (2016-10-19)",
"translation": "## 破坏性变化:`in-memory-web-api` (v.0.1.11) 以esm umd的形式发布 (2016-10-19)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "This change supports ES6 developers and aligns better with typical Angular libraries.\nIt does not affect the module's API but it does affect how you load and import it.\nSee the change note\nin the `in-memory-web-api` repo.",
"translation": "这个变化支持ES6开发者,并与典型的Angular库看齐。\n它不会影响模块的API,但是它改变了加载和导入它的方式。\n参见`in-memory-web-api`库的变更记录。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## \"Router\" _preload_ syntax and _:enter_/_:leave_ animations (2016-10-19)",
"translation": "## \"路由器\"_预加载_语法和_:enter_/_:leave_动画(2016-10-19)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The router can lazily _preload_ modules _after_ the app starts and\n_before_ the user navigates to them for improved perceived performance.",
"translation": "路由器可以在应用启动_之后_和用户导航到惰性加载模块_之前_,预先加载惰性模块,以增强性能。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "New `:enter` and `:leave` aliases make animation more natural.",
"translation": "新`:enter`和`:leave`语法,让动画更加自然。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## Sync with Angular v.2.1.0 (2016-10-12)",
"translation": "## 与Angular v.2.1.0同步(2016-10-12)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Docs and code samples updated and tested with Angular v.2.1.0.",
"translation": "使用Angular v.2.1.0更新和测试所有文档和代码例子。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## NEW \"Ahead of time (AOT) Compilation\" guide (2016-10-11)",
"translation": "## 添加了新的“预编译(AoT)\"烹饪书(2016-10-11)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The NEW [Ahead of time (AOT) Compilation](guide/aot-compiler) guide\nexplains what AOT compilation is and why you'd want it.\nIt demonstrates the basics with a QuickStart app\nfollowed by the more advanced considerations of compiling and bundling the Tour of Heroes.",
"translation": "全新[预编译(AoT)](guide/aot-compiler)烹饪书介绍了什么是AoT编译和为何你需要它。\n它以**快速上手**应用程序开始讲解,接着介绍了编译和构建**英雄指南**的更高级的注意事项。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## Sync with Angular v.2.0.2 (2016-10-6)",
"translation": "## 与Angular v.2.0.2同步 (2016-10-6)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Docs and code samples updated and tested with Angular v.2.0.2.",
"translation": "使用Angular v.2.0.2更新和测试所有文档和代码例子。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## \"Routing and Navigation\" guide with the _Router Module_ (2016-10-5)",
"translation": "## 在“路由和导航”向导中添加**路由模块** (2016-10-5)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The [Routing and Navigation](guide/router) guide now locates route configuration\nin a _Routing Module_.\nThe _Routing Module_ replaces the previous _routing object_ involving the `ModuleWithProviders`.",
"translation": "[Routing and Navigation](guide/router)现在在**路由模块**中设置路由配置。\n**路由模块**替换之前的**路由对象**,使用了`ModuleWithProviders`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "All guided samples with routing use the _Routing Module_ and prose content has been updated,\nmost conspicuously in the\n[NgModule](guide/ngmodules) guide and [NgModule FAQ](guide/ngmodule-faq) guide.",
"translation": "所有使用路由的例子都使用**路由模块**,相关内容也被更新。更新最多的是[Angular模块(NgModule)](guide/ngmodules)章和[Angular模块常见问题](guide/ngmodule-faq)烹饪书。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## New \"Internationalization\" guide (2016-09-30)",
"translation": "## 全新“国际化”烹饪书(2016-09-30)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Added a new [Internationalization (i18n)](guide/i18n) guide that shows how\nto use Angular \"i18n\" facilities to translate template text into multiple languages.",
"translation": "添加了新的[国际化(i18n)](guide/i18n)烹饪书,展示了如何使用Angular的“i18n”工具来讲模板文本翻译到多种语言。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## \"angular-in-memory-web-api\" package rename (2016-09-27)",
"translation": "## 重命名“angular-in-memory-web-api”包(2016-09-27)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Many samples use the `angular-in-memory-web-api` to simulate a remote server.\nThis library is also useful to you during early development before you have a server to talk to.",
"translation": "许多例子使用了`angular-in-memory-web-api`来模拟远程服务器。\n这个库在你拥有服务器之前的早期开发阶段也很有用。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The package name was changed from \"angular2-in-memory-web-api\" which is still frozen-in-time on npm.\nThe new \"angular-in-memory-web-api\" has new features.\nRead about them on github.",
"translation": "这个包的名字从“angular2-in-memory-web-api”(仍然有效,但不再更新了)重新命名了。\n新的“angular-in-memory-web-api”有新的功能。\n到github获得更多详情.",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## \"Style Guide\" with _NgModules_ (2016-09-27)",
"translation": "## “风格指南”中添加了_NgModules_(2016-09-27)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "[StyleGuide](guide/styleguide) explains recommended conventions for NgModules.\nBarrels now are far less useful and have been removed from the style guide;\nthey remain valuable but are not a matter of Angular style.\nAlso relaxed the rule that discouraged use of the `@Component.host` property.",
"translation": "[StyleGuide](guide/styleguide)解释了我们为Angular模块(NgModule)而推荐的约定。\n现在,封装桶不再那么重要,风格指南已经移除了它们。\n它们仍然很有价值,但是它们与Angular风格无关。\n我们同时对**不推荐使用`@Component.host`属性**的规则有所放宽。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## _moduleId: module.id_ everywhere (2016-09-25)",
"translation": "## moduleId:到处添加module.id(2016-09-25)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "Sample components that get their templates or styles with `templateUrl` or `styleUrls`\nhave been converted to _module-relative_ URLs.\nAdded the `moduleId: module.id` property-and-value to their `@Component` metadata.",
"translation": "在所有使用`templateUrl`或者`styleUrls`来获取模板或样式的例子组件都被转换为**相对模块**的URL。\n我们添加了`moduleId: module.id`到它们的`@Component`元数据。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "This change is a requirement for compilation with AOT compiler when the app loads\nmodules with SystemJS as the samples currently do.",
"translation": "当应用像例子当前使用的方法一样 - 使用SystemJS加载模块时,本更新是AoT编译器的前提条件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "## \"Lifecycle Hooks\" guide simplified (2016-09-24)",
"translation": "## 简化了“生命周期钩子”章(2016-09-24)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "The [Lifecycle Hooks](guide/lifecycle-hooks) guide is shorter, simpler, and\ndraws more attention to the order in which Angular calls the hooks.",
"translation": "[生命周期钩子](guide/lifecycle-hooks)章现在更加简短,并且对强调了Angular是以什么顺序来调用钩子方法的。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/change-log.md"
},
{
"original": "
Creates a local variable movieplayer that provides access to the video element instance in data-binding and event-binding expressions in the current template.
Binds the presence of CSS classes on the element to the truthiness of the associated map values. The right-hand expression should return {class-name: true/false} map.
",
"translation": "
根据 map 中的 value 是否为真,来决定该元素上是否出现与 name 对应的 CSS 类。右侧的表达式应该返回一个形如 {class-name: true/false} 的 map。
Allows you to assign styles to an HTML element using CSS. You can use CSS directly, as in the first example, or you can call a method from the component.
",
"translation": "
允许你使用 CSS 为 HTML 元素指定样式。你可以像第一个例子那样直接使用 CSS,也可以调用组件中的方法。
Creates a link to a different view based on a route instruction consisting of a route path, required and optional parameters, query parameters, and a fragment. To navigate to a root route, use the / prefix; for a child route, use the ./prefix; for a sibling or parent, use the ../ prefix.
An interface for defining a class that the router should call first to determine if it should activate this component. Should return a boolean or an Observable/Promise that resolves to a boolean.
An interface for defining a class that the router should call first to determine if it should deactivate this component after a navigation. Should return a boolean or an Observable/Promise that resolves to a boolean.
An interface for defining a class that the router should call first to determine if it should activate the child route. Should return a boolean or an Observable/Promise that resolves to a boolean.
An interface for defining a class that the router should call first to resolve route data before rendering the route. Should return a value or an Observable/Promise that resolves to a value.
An interface for defining a class that the router should call first to check if the lazy loaded module should be loaded. Should return a boolean or an Observable/Promise that resolves to a boolean.
",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/cheatsheet.md"
},
{
"original": "### Error handling",
"translation": "### 错误处理",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/comparing-observables.md"
},
{
"original": "# Component Interaction",
"translation": "# 组件之间的交互",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "This cookbook contains recipes for common component communication scenarios\nin which two or more components share information.",
"translation": "本烹饪宝典包含了常见的组件通讯场景,也就是让两个或多个组件之间共享信息的方法。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "# Contents",
"translation": "# 目录",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "* [Pass data from parent to child with input binding](guide/component-interaction#parent-to-child)",
"translation": "[使用输入绑定把数据从父组件传给子组件](guide/component-interaction#parent-to-child)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "* [Intercept input property changes with a setter](guide/component-interaction#parent-to-child-setter)",
"translation": "[使用赋值器(setter)拦截输入属性的变化](guide/component-interaction#parent-to-child-setter)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "* [Intercept input property changes with `ngOnChanges()`](guide/component-interaction#parent-to-child-on-changes)",
"translation": "[使用`ngOnChanges()`拦截输入属性的变化](guide/component-interaction#parent-to-child-on-changes)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "* [Parent calls an `@ViewChild()`](guide/component-interaction#parent-to-view-child)",
"translation": "[在父组件中调用`@ViewChild()`](guide/component-interaction#parent-to-view-child)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "* [Parent and children communicate via a service](guide/component-interaction#bidirectional-service)",
"translation": "[通过服务进行父子通讯](guide/component-interaction#bidirectional-service)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "**See the **.",
"translation": "**参见**。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "## Pass data from parent to child with input binding",
"translation": "## 通过输入型绑定把数据从父组件传到子组件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "`HeroChildComponent` has two ***input properties***,\ntypically adorned with [@Input decorations](guide/template-syntax#inputs-outputs).",
"translation": "`HeroChildComponent` 有两个***输入型属性***,它们通常带[@Input装饰器](guide/template-syntax#inputs-outputs)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The second `@Input` aliases the child component property name `masterName` as `'master'`.",
"translation": "第二个`@Input`为子组件的属性名`masterName`指定一个别名`master`(译者注:不推荐为起别名,请参见风格指南).",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The `HeroParentComponent` nests the child `HeroChildComponent` inside an `*ngFor` repeater,\nbinding its `master` string property to the child's `master` alias,\nand each iteration's `hero` instance to the child's `hero` property.",
"translation": "父组件`HeroParentComponent`把子组件的`HeroChildComponent`放到`*ngFor`循环器中,把自己的`master`字符串属性绑定到子组件的`master`别名上,并把每个循环的`hero`实例绑定到子组件的`hero`属性。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The running application displays three heroes:",
"translation": "运行应用程序会显示三个英雄:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "
Test it
",
"translation": "
测试一下!
",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "E2E test that all children were instantiated and displayed as expected:",
"translation": "端到端测试,用于确保所有的子组件都像所期待的那样被初始化并显示出来。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "[Back to top](guide/component-interaction#top)",
"translation": "[回到顶部](guide/component-interaction#top)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "## Intercept input property changes with a setter",
"translation": "## 通过setter截听输入属性值的变化",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Use an input property setter to intercept and act upon a value from the parent.",
"translation": "使用一个输入属性的setter,以拦截父组件中值的变化,并采取行动。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The setter of the `name` input property in the child `NameChildComponent`\ntrims the whitespace from a name and replaces an empty value with default text.",
"translation": "子组件`NameChildComponent`的输入属性`name`上的这个setter,会trim掉名字里的空格,并把空值替换成默认字符串。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Here's the `NameParentComponent` demonstrating name variations including a name with all spaces:",
"translation": "下面的`NameParentComponent`展示了各种名字的处理方式,包括一个全是空格的名字。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "
Test it
",
"translation": "
测试一下!
",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "E2E tests of input property setter with empty and non-empty names:",
"translation": "端到端测试:输入属性的setter,分别使用空名字和非空名字。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "[Back to top](guide/component-interaction#top)",
"translation": "[回到顶部](guide/component-interaction#top)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "## Intercept input property changes with *ngOnChanges()*",
"translation": "## 通过*ngOnChanges()*来截听输入属性值的变化",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Detect and act upon changes to input property values with the `ngOnChanges()` method of the `OnChanges` lifecycle hook interface.",
"translation": "使用`OnChanges`生命周期钩子接口的`ngOnChanges()`方法来监测输入属性值的变化并做出回应。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "You may prefer this approach to the property setter when watching multiple, interacting input properties.",
"translation": "当需要监视多个、交互式输入属性的时候,本方法比用属性的setter更合适。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Learn about `ngOnChanges()` in the [LifeCycle Hooks](guide/lifecycle-hooks) chapter.",
"translation": "学习关于`ngOnChanges()`的更多知识,参见[生命周期钩子](guide/lifecycle-hooks)一章。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "This `VersionChildComponent` detects changes to the `major` and `minor` input properties and composes a log message reporting these changes:",
"translation": "这个`VersionChildComponent`会监测输入属性`major`和`minor`的变化,并把这些变化编写成日志以报告这些变化。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The `VersionParentComponent` supplies the `minor` and `major` values and binds buttons to methods that change them.",
"translation": "`VersionParentComponent`提供`minor`和`major`值,把修改它们值的方法绑定到按钮上。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Here's the output of a button-pushing sequence:",
"translation": "下面是点击按钮的结果。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "
Test it
",
"translation": "
测试一下!
",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Test that ***both*** input properties are set initially and that button clicks trigger\nthe expected `ngOnChanges` calls and values:",
"translation": "测试确保***这两个***输入属性值都被初始化了,当点击按钮后,`ngOnChanges`应该被调用,属性的值也符合预期。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "[Back to top](guide/component-interaction#top)",
"translation": "[回到顶部](guide/component-interaction#top)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "## Parent listens for child event",
"translation": "## 父组件监听子组件的事件",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The child component exposes an `EventEmitter` property with which it `emits` events when something happens.\nThe parent binds to that event property and reacts to those events.",
"translation": "子组件暴露一个`EventEmitter`属性,当事件发生时,子组件利用该属性`emits`(向上弹射)事件。父组件绑定到这个事件属性,并在事件发生时作出回应。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The child's `EventEmitter` property is an ***output property***,\n typically adorned with an [@Output decoration](guide/template-syntax#inputs-outputs)\n as seen in this `VoterComponent`:",
"translation": "子组件的`EventEmitter`属性是一个**输出属性**,通常带有[@Output装饰器](guide/template-syntax#inputs-outputs),就像在`VoterComponent`中看到的。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Clicking a button triggers emission of a `true` or `false`, the boolean *payload*.",
"translation": "点击按钮会触发`true`或`false`(布尔型*有效载荷*)的事件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The parent `VoteTakerComponent` binds an event handler called `onVoted()` that responds to the child event\npayload `$event` and updates a counter.",
"translation": "父组件`VoteTakerComponent`绑定了一个事件处理器(`onVoted()`),用来响应子组件的事件(`$event`)并更新一个计数器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The framework passes the event argument—represented by `$event`—to the handler method,\nand the method processes it:",
"translation": "框架(Angular)把事件参数(用`$event`表示)传给事件处理方法,这个方法会处理:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "
Test it
",
"translation": "
测试一下!
",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Test that clicking the *Agree* and *Disagree* buttons update the appropriate counters:",
"translation": "测试确保点击*Agree*和*Disagree*按钮时,计数器被正确更新。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "[Back to top](guide/component-interaction#top)",
"translation": "[回到顶部](guide/component-interaction#top)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "## Parent interacts with child via *local variable*",
"translation": "## 父组件与子组件通过*本地变量*互动",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "A parent component cannot use data binding to read child properties\nor invoke child methods. You can do both\nby creating a template reference variable for the child element\nand then reference that variable *within the parent template*\nas seen in the following example.",
"translation": "父组件不能使用数据绑定来读取子组件的属性或调用子组件的方法。但可以在父组件模板里,新建一个本地变量来代表子组件,然后利用这个变量来读取子组件的属性和调用子组件的方法,如下例所示。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The following is a child `CountdownTimerComponent` that repeatedly counts down to zero and launches a rocket.\nIt has `start` and `stop` methods that control the clock and it displays a\ncountdown status message in its own template.",
"translation": "子组件`CountdownTimerComponent`进行倒计时,归零时发射一个导弹。`start`和`stop`方法负责控制时钟并在模板里显示倒计时的状态信息。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The `CountdownLocalVarParentComponent` that hosts the timer component is as follows:",
"translation": "让我们来看看计时器组件的宿主组件`CountdownLocalVarParentComponent`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The parent component cannot data bind to the child's\n`start` and `stop` methods nor to its `seconds` property.",
"translation": "父组件不能通过数据绑定使用子组件的`start`和`stop`方法,也不能访问子组件的`seconds`属性。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "You can place a local variable, `#timer`, on the tag `` representing the child component.\nThat gives you a reference to the child component and the ability to access\n*any of its properties or methods* from within the parent template.",
"translation": "把本地变量(`#timer`)放到(``)标签中,用来代表子组件。这样父组件的模板就得到了子组件的引用,于是可以在父组件的模板中访问子组件的所有属性和方法。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "This example wires parent buttons to the child's `start` and `stop` and\nuses interpolation to display the child's `seconds` property.",
"translation": "在这个例子中,我们把父组件的按钮绑定到子组件的`start`和`stop`方法,并用插值表达式来显示子组件的`seconds`属性。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Here we see the parent and child working together.",
"translation": "下面是父组件和子组件一起工作时的效果。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "
Test it
",
"translation": "
测试一下!
",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Test that the seconds displayed in the parent template\nmatch the seconds displayed in the child's status message.\nTest also that clicking the *Stop* button pauses the countdown timer:",
"translation": "测试确保在父组件模板中显示的秒数和子组件状态信息里的秒数同步。它还会点击*Stop*按钮来停止倒计时:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "[Back to top](guide/component-interaction#top)",
"translation": "[回到顶部](guide/component-interaction#top)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "## Parent calls an _@ViewChild()_",
"translation": "## 父组件调用*@ViewChild()*",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The *local variable* approach is simple and easy. But it is limited because\nthe parent-child wiring must be done entirely within the parent template.\nThe parent component *itself* has no access to the child.",
"translation": "这个*本地变量*方法是个简单便利的方法。但是它也有局限性,因为父组件-子组件的连接必须全部在父组件的模板中进行。父组件本身的代码对子组件没有访问权。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "You can't use the *local variable* technique if an instance of the parent component *class*\nmust read or write child component values or must call child component methods.",
"translation": "如果父组件的*类*需要读取子组件的属性值或调用子组件的方法,就不能使用*本地变量*方法。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "When the parent component *class* requires that kind of access,\n***inject*** the child component into the parent as a *ViewChild*.",
"translation": "当父组件*类*需要这种访问时,可以把子组件作为*ViewChild*,***注入***到父组件里面。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The following example illustrates this technique with the same\n[Countdown Timer](guide/component-interaction#countdown-timer-example) example.\nNeither its appearance nor its behavior will change.\nThe child [CountdownTimerComponent](guide/component-interaction#countdown-timer-example) is the same as well.",
"translation": "下面的例子用与[倒计时](guide/component-interaction#countdown-timer-example)相同的范例来解释这种技术。\n我们没有改变它的外观或行为。子组件[CountdownTimerComponent](guide/component-interaction#countdown-timer-example)也和原来一样。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The switch from the *local variable* to the *ViewChild* technique\nis solely for the purpose of demonstration.",
"translation": "由*本地变量*切换到*ViewChild*技术的唯一目的就是做示范。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Here is the parent, `CountdownViewChildParentComponent`:",
"translation": "下面是父组件`CountdownViewChildParentComponent`:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "It takes a bit more work to get the child view into the parent component *class*.",
"translation": "把子组件的视图插入到父组件类需要做一点额外的工作。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "First, you have to import references to the `ViewChild` decorator and the `AfterViewInit` lifecycle hook.",
"translation": "首先,你要使用`ViewChild`装饰器导入这个引用,并挂上`AfterViewInit`生命周期钩子。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Next, inject the child `CountdownTimerComponent` into the private `timerComponent` property\nvia the `@ViewChild` property decoration.",
"translation": "接着,通过`@ViewChild`属性装饰器,将子组件`CountdownTimerComponent`注入到私有属性`timerComponent`里面。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The `#timer` local variable is gone from the component metadata.\nInstead, bind the buttons to the parent component's own `start` and `stop` methods and\npresent the ticking seconds in an interpolation around the parent component's `seconds` method.",
"translation": "组件元数据里就不再需要`#timer`本地变量了。而是把按钮绑定到父组件自己的`start`和`stop`方法,使用父组件的`seconds`方法的插值表达式来展示秒数变化。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "These methods access the injected timer component directly.",
"translation": "这些方法可以直接访问被注入的计时器组件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The `ngAfterViewInit()` lifecycle hook is an important wrinkle.\nThe timer component isn't available until *after* Angular displays the parent view.\nSo it displays `0` seconds initially.",
"translation": "`ngAfterViewInit()`生命周期钩子是非常重要的一步。被注入的计时器组件只有在Angular显示了父组件视图之后才能访问,所以我们先把秒数显示为0.",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Then Angular calls the `ngAfterViewInit` lifecycle hook at which time it is *too late*\nto update the parent view's display of the countdown seconds.\nAngular's unidirectional data flow rule prevents updating the parent view's\nin the same cycle. The app has to *wait one turn* before it can display the seconds.",
"translation": "然后Angular会调用`ngAfterViewInit`生命周期钩子,但这时候再更新父组件视图的倒计时就已经太晚了。Angular的单向数据流规则会阻止在同一个周期内更新父组件视图。我们在显示秒数之前会被迫*再等一轮*。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Use `setTimeout()` to wait one tick and then revise the `seconds()` method so\nthat it takes future values from the timer component.",
"translation": "使用`setTimeout()`来等下一轮,然后改写`seconds()`方法,这样它接下来就会从注入的这个计时器组件里获取秒数的值。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "
Test it
",
"translation": "
测试一下!
",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Use [the same countdown timer tests](guide/component-interaction#countdown-tests) as before.",
"translation": "使用和之前[一样的倒计时测试](guide/component-interaction#countdown-tests)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "[Back to top](guide/component-interaction#top)",
"translation": "[回到顶部](guide/component-interaction#top)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "## Parent and children communicate via a service",
"translation": "## 父组件和子组件通过服务来通讯",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "A parent component and its children share a service whose interface enables bi-directional communication\n*within the family*.",
"translation": "父组件和它的子组件共享同一个服务,利用该服务*在家庭内部*实现双向通讯。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The scope of the service instance is the parent component and its children.\nComponents outside this component subtree have no access to the service or their communications.",
"translation": "该服务实例的作用域被限制在父组件和其子组件内。这个组件子树之外的组件将无法访问该服务或者与它们通讯。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "This `MissionService` connects the `MissionControlComponent` to multiple `AstronautComponent` children.",
"translation": "这个`MissionService`把`MissionControlComponent`和多个`AstronautComponent`子组件连接起来。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The `MissionControlComponent` both provides the instance of the service that it shares with its children\n(through the `providers` metadata array) and injects that instance into itself through its constructor:",
"translation": "`MissionControlComponent`提供服务的实例,并将其共享给它的子组件(通过`providers`元数据数组),子组件可以通过构造函数将该实例注入到自身。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The `AstronautComponent` also injects the service in its constructor.\nEach `AstronautComponent` is a child of the `MissionControlComponent` and therefore receives its parent's service instance:",
"translation": "`AstronautComponent`也通过自己的构造函数注入该服务。由于每个`AstronautComponent`都是`MissionControlComponent`的子组件,所以它们获取到的也是父组件的这个服务实例。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Notice that this example captures the `subscription` and `unsubscribe()` when the `AstronautComponent` is destroyed.\nThis is a memory-leak guard step. There is no actual risk in this app because the\nlifetime of a `AstronautComponent` is the same as the lifetime of the app itself.\nThat *would not* always be true in a more complex application.",
"translation": "注意,这个例子保存了`subscription`变量,并在`AstronautComponent`被销毁时调用`unsubscribe()`退订。\n这是一个用于防止内存泄漏的保护措施。实际上,在这个应用程序中并没有这个风险,因为`AstronautComponent`的生命期和应用程序的生命期一样长。但在更复杂的应用程序环境中就不一定了。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "You don't add this guard to the `MissionControlComponent` because, as the parent,\nit controls the lifetime of the `MissionService`.",
"translation": "不需要在`MissionControlComponent`中添加这个保护措施,因为它作为父组件,控制着`MissionService`的生命期。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "The *History* log demonstrates that messages travel in both directions between\nthe parent `MissionControlComponent` and the `AstronautComponent` children,\nfacilitated by the service:",
"translation": "*History*日志证明了:在父组件`MissionControlComponent`和子组件`AstronautComponent`之间,信息通过该服务实现了双向传递。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "
Test it
",
"translation": "
测试一下!
",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "Tests click buttons of both the parent `MissionControlComponent` and the `AstronautComponent` children\nand verify that the history meets expectations:",
"translation": "测试确保点击父组件`MissionControlComponent`和子组件`AstronautComponent`两个的组件的按钮时,*History*日志和预期的一样。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "[Back to top](guide/component-interaction#top)",
"translation": "[回到顶部](guide/component-interaction#top)",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-interaction.md"
},
{
"original": "# Component Styles",
"translation": "# 组件样式",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Angular applications are styled with standard CSS. That means you can apply\neverything you know about CSS stylesheets, selectors, rules, and media queries\ndirectly to Angular applications.",
"translation": "Angular 应用使用标准的 CSS 来设置样式。这意味着我们可以把关于 CSS\n的那些知识和技能直接用于我们的 Angular 程序中,例如:样式表、选择器、规则以及媒体查询等。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Additionally, Angular can bundle *component styles*\nwith components, enabling a more modular design than regular stylesheets.",
"translation": "另外,Angular 还能把*组件样式*捆绑在我们的组件上,以实现比标准样式表更加模块化的设计。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "This page describes how to load and apply these component styles.",
"translation": "在本章中,我们将学到如何加载和使用这些*组件样式*。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "You can run the in Stackblitz and download the code from there.",
"translation": "运行来试用本页的代码。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "## Using component styles",
"translation": "## 使用组件样式",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "For every Angular component you write, you may define not only an HTML template,\nbut also the CSS styles that go with that template,\nspecifying any selectors, rules, and media queries that you need.",
"translation": "对于我们写的每个 Angular 组件来说,除了定义 HTML 模板之外,我们还要定义用于模板的 CSS 样式、\n指定任意的选择器、规则和媒体查询。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "One way to do this is to set the `styles` property in the component metadata.\nThe `styles` property takes an array of strings that contain CSS code.\nUsually you give it one string, as in the following example:",
"translation": "实现方式之一,是在组件的元数据中设置`styles`属性。\n`styles`属性可以接受一个包含 CSS 代码的字符串数组。\n通常我们只给它一个字符串就行了,如同下例:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "## Style scope",
"translation": "## 范围化的样式",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "The styles specified in `@Component` metadata _apply only within the template of that component_.",
"translation": "在 `@Component` 的元数据中指定的样式只会对该组件的模板生效。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "They are _not inherited_ by any components nested within the template nor by any content projected into the component.",
"translation": "它们既不会被模板中嵌入的组件继承,也不会被通过内容投影(如 ng-content)嵌进来的组件继承。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "In this example, the `h1` style applies only to the `HeroAppComponent`,\nnot to the nested `HeroMainComponent` nor to `
` tags anywhere else in the application.",
"translation": "在这个例子中,`h1` 的样式只对 `HeroAppComponent` 生效,既不会作用于内嵌的 `HeroMainComponent` ,也不会作用于应用中其它任何地方的 `
` 标签。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "This scoping restriction is a ***styling modularity feature***.",
"translation": "这种范围限制就是所谓的***样式模块化***特性",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "* You can use the CSS class names and selectors that make the most sense in the context of each component.",
"translation": "可以使用对每个组件最有意义的 CSS 类名和选择器。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "* Class names and selectors are local to the component and don't collide with\n classes and selectors used elsewhere in the application.",
"translation": "类名和选择器是仅属于组件内部的,它不会和应用中其它地方的类名和选择器出现冲突。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "* Changes to styles elsewhere in the application don't affect the component's styles.",
"translation": "我们组件的样式*不会*因为别的地方修改了样式而被意外改变。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "* You can co-locate the CSS code of each component with the TypeScript and HTML code of the component,\n which leads to a neat and tidy project structure.",
"translation": "我们可以让每个组件的 CSS 代码和它的 TypeScript、HTML 代码放在一起,这将促成清爽整洁的项目结构。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "* You can change or remove component CSS code without searching through the\n whole application to find where else the code is used.",
"translation": "将来我们可以修改或移除组件的 CSS 代码,而不用遍历整个应用来看它有没有被别处用到,只要看看当前组件就可以了。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "## Special selectors",
"translation": "## 特殊的选择器",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Component styles have a few special *selectors* from the world of shadow DOM style scoping\n(described in the [CSS Scoping Module Level 1](https://www.w3.org/TR/css-scoping-1) page on the\n[W3C](https://www.w3.org) site).\nThe following sections describe these selectors.",
"translation": "组件样式中有一些从影子(Shadow) DOM 样式范围领域(记录在[W3C](https://www.w3.org)的[CSS Scoping Module Level 1](https://www.w3.org/TR/css-scoping-1)中) 引入的特殊*选择器*:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "### :host",
"translation": "### :host 选择器",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Use the `:host` pseudo-class selector to target styles in the element that *hosts* the component (as opposed to\ntargeting elements *inside* the component's template).",
"translation": "使用`:host`伪类选择器,用来选择组件*宿主*元素中的元素(相对于组件模板*内部*的元素)。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "The `:host` selector is the only way to target the host element. You can't reach\nthe host element from inside the component with other selectors because it's not part of the\ncomponent's own template. The host element is in a parent component's template.",
"translation": "这是我们能以宿主元素为目标的*唯一*方式。除此之外,我们将没办法指定它,\n因为宿主不是组件自身模板的一部分,而是父组件模板的一部分。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Use the *function form* to apply host styles conditionally by\nincluding another selector inside parentheses after `:host`.",
"translation": "要把宿主样式作为条件,就要像*函数*一样把其它选择器放在`:host`后面的括号中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "The next example targets the host element again, but only when it also has the `active` CSS class.",
"translation": "在下一个例子中,我们又一次把宿主元素作为目标,但是只有当它同时带有`active` CSS 类的时候才会生效。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "### :host-context",
"translation": "### :host-context 选择器",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Sometimes it's useful to apply styles based on some condition *outside* of a component's view.\nFor example, a CSS theme class could be applied to the document `` element, and\nyou want to change how your component looks based on that.",
"translation": "有时候,基于某些来自组件视图*外部*的条件应用样式是很有用的。\n例如,在文档的``元素上可能有一个用于表示样式主题 (theme) 的 CSS 类,而我们应当基于它来决定组件的样式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Use the `:host-context()` pseudo-class selector, which works just like the function\nform of `:host()`. The `:host-context()` selector looks for a CSS class in any ancestor of the component host element,\nup to the document root. The `:host-context()` selector is useful when combined with another selector.",
"translation": "这时可以使用`:host-context()`伪类选择器。它也以类似`:host()`形式使用。它在当前组件宿主元素的*祖先节点*中查找 CSS 类,\n直到文档的根节点为止。在与其它选择器组合使用时,它非常有用。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "The following example applies a `background-color` style to all `
` elements *inside* the component, only\nif some ancestor element has the CSS class `theme-light`.",
"translation": "在下面的例子中,只有当某个祖先元素有 CSS 类`theme-light`时,我们才会把`background-color`样式应用到组件*内部*的所有`
`元素中。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "### (deprecated) `/deep/`, `>>>`, and `::ng-deep`",
"translation": "### 已废弃 `/deep/`、`>>>`和`::ng-deep`",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Component styles normally apply only to the HTML in the component's own template.",
"translation": "组件样式通常只会作用于组件自身的 HTML 上。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Use the `/deep/` shadow-piercing descendant combinator to force a style down through the child\ncomponent tree into all the child component views.\nThe `/deep/` combinator works to any depth of nested components, and it applies to both the view\nchildren and content children of the component.",
"translation": "我们可以使用`/deep/`选择器,来强制一个样式对各级子组件的视图也生效,它*不但作用于组件的子视图,也会作用于组件的内容*。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "The following example targets all `
` elements, from the host element down\nthrough this component to all of its child elements in the DOM.",
"translation": "在这个例子中,我们以所有的`
`元素为目标,从宿主元素到当前元素再到 DOM 中的所有子元素:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "The `/deep/` combinator also has the aliases `>>>`, and `::ng-deep`.",
"translation": "`/deep/` 组合器还有两个别名:`>>>`和`::ng-deep`。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Use `/deep/`, `>>>` and `::ng-deep` only with *emulated* view encapsulation.\nEmulated is the default and most commonly used view encapsulation. For more information, see the\n[Controlling view encapsulation](guide/component-styles#view-encapsulation) section.",
"translation": "`/deep/`和`>>>`选择器只能被用在**仿真 (emulated) **模式下。\n这种方式是默认值,也是用得最多的方式。\n更多信息,见[控制视图封装模式](guide/component-styles#view-encapsulation)一节。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "The shadow-piercing descendant combinator is deprecated and [support is being removed from major browsers](https://www.chromestatus.com/features/6750456638341120) and tools.\nAs such we plan to drop support in Angular (for all 3 of `/deep/`, `>>>` and `::ng-deep`).\nUntil then `::ng-deep` should be preferred for a broader compatibility with the tools.",
"translation": "CSS标准中用于 \"刺穿Shadow DOM\" 的组合器已经被废弃,并将[这个特性从主流浏览器和工具中移除](https://www.chromestatus.com/features/6750456638341120)。\n因此,我们也将在 Angular 中移除对它们的支持(包括`/deep/`、`>>>` 和 `::ng-deep`)。\n目前,建议先统一使用`::ng-deep`,以便兼容将来的工具。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "## Loading component styles",
"translation": "## 把样式加载进组件中",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "There are several ways to add styles to a component:",
"translation": "有几种方式把样式加入组件:",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "* By setting `styles` or `styleUrls` metadata.",
"translation": "设置`styles`或`styleUrls`元数据",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "* Inline in the template HTML.",
"translation": "内联在模板的 HTML 中",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "* With CSS imports.",
"translation": "通过 CSS 文件导入",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "The scoping rules outlined earlier apply to each of these loading patterns.",
"translation": "上述作用域规则对所有这些加载模式都适用。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "### Styles in component metadata",
"translation": "### 元数据中的样式",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "You can add a `styles` array property to the `@Component` decorator.",
"translation": "我们可以给`@Component`装饰器添加一个`styles`数组型属性。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Each string in the array defines some CSS for this component.",
"translation": "这个数组中的每一个字符串(通常也只有一个)定义一份 CSS。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Reminder: these styles apply _only to this component_.\nThey are _not inherited_ by any components nested within the template nor by any content projected into the component.",
"translation": "注意:这些样式**只对当前组件生效**。\n它们**既不会作用于模板中嵌入的任何组件**,也不会作用于投影进来的组件(如 `ng-content` )。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "The CLI defines an empty `styles` array when you create the component with the `--inline-styles` flag.",
"translation": "当使用 `--inline-styles` 标识创建组件时,CLI 就会定义一个空的 `styles` 数组",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "### Style files in component metadata",
"translation": "### 组件元数据中的样式文件",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "You can load styles from external CSS files by adding a `styleUrls` property\nto a component's `@Component` decorator:",
"translation": "我们可以通过把外部 CSS 文件添加到 `@Component` 的 `styleUrls` 属性中来加载外部样式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "Reminder: the styles in the style file apply _only to this component_.\nThey are _not inherited_ by any components nested within the template nor by any content projected into the component.",
"translation": "注意:这些样式**只对当前组件生效**。\n它们**既不会作用于模板中嵌入的任何组件**,也不会作用于投影进来的组件(如 `ng-content` )。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "You can specify more than one styles file or even a combination of `style` and `styleUrls`.",
"translation": "我们可以指定多个样式文件,甚至可以组合使用 `style` 和 `styleUrls` 方式。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "The CLI creates an empty styles file for you by default and references that file in the component's generated `styleUrls`.",
"translation": "CLI 会默认为你创建一个空白的样式表文件,并且在所生成组件的 `styleUrls` 中引用该文件。",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "### Template inline styles",
"translation": "### 模板内联样式",
"sourceFile": "/Users/twer/private/GDE/angular-cn/aio/content/guide/component-styles.md"
},
{
"original": "You can embed CSS styles directly into the HTML template by putting them\ninside `