` element is hidden if the `favoriteHero` variable is not truthy.",
"translation": "在这个例子中,如果`favoriteHero`变量不是真值,`
`元素就会被隐藏。",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "### Bind to the `src` property",
"translation": "### 绑定到`src`属性",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/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/content-1/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/content-1/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/content-1/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/content-1/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/content-1/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/content-1/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/content-1/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/content-1/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/content-1/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/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "The (*) before `ngSwitchCase` and `ngSwitchDefault` is required in this example.",
"translation": "在这个例子中,`ngSwitchCase`和`ngSwitchDefault`前面的星号(*)是必须的。",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "## Filters/pipes",
"translation": "## 过滤器/管道",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "Formats a number as currency.",
"translation": "把一个数字格式化成货币。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "The Angular `currency` pipe is similar although some of the parameters have changed.",
"translation": "Angular的`currency`管道和1中很相似,只是有些参数变化了。\n ",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "Formats a date to a string based on the requested format.",
"translation": "基于要求的格式把日期格式化成字符串。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "The Angular `date` pipe is similar.",
"translation": "Angular的`date`管道和它很相似。",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "
",
"translation": "### none\n ### 没了\n 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.",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "### none\n ### 没了\n 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/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "The Angular `json` pipe does the same thing.",
"translation": "Angular的`json`管道做完全相同的事。\n | ",
"sourceFile": "/Users/twer/private/GDE/content-1/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)个条目。\n ",
"sourceFile": "/Users/twer/private/GDE/content-1/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中一样,如果们改用组件中的代码实现此操作,性能将会提升。\n ",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "Converts the string to lowercase.",
"translation": "把该字符串转成小写形式。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "The Angular `lowercase` pipe does the same thing.",
"translation": "Angular的`lowercase`管道和1中的功能完全相同。\n ",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "Formats a number as text.",
"translation": "把数字格式化为文本。",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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)百分比格式,如第三个范例所示。\n ",
"sourceFile": "/Users/twer/private/GDE/content-1/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排序了。\n ",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "
",
"translation": "### none\n ### 没了\n 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.",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "### none\n ### 没了\n 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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "## Modules/controllers/components",
"translation": "## 模块/控制器/组件",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/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/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "### none",
"translation": "### 没了",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "### Angular modules",
"translation": "### Angular模块",
"sourceFile": "/Users/twer/private/GDE/content-1/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模块用来对控制器、服务和其它代码进行跟踪。第二个参数定义该模块依赖的其它模块列表。\n | ",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "NgModules, defined with the `NgModule` decorator, serve the same purpose:",
"translation": "Angular的模块用`NgModule`装饰器进行定义,有如下用途:",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "* `declaration`: keeps track of your components, pipes, and directives.",
"translation": "`declaration`: 用于记录组件、管道和指令。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "For more information on modules, see [NgModules](guide/ngmodule).",
"translation": "要了解关于模块的更多知识,参见[NgModules](guide/ngmodule)。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "
",
"translation": "### Controller registration\n### 控制器注册 \n angular\n .module(\"movieHunter\")\n .controller(\"MovieListCtrl\",\n [\"movieService\",\n MovieListCtrl]);\n ",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "### Component decorator",
"translation": "### 组件装饰器",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "### Controller function",
"translation": "### 控制器函数",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "In AngularJS, you write the code for the model and methods in a controller function.",
"translation": "在Angular1中,我们在控制器函数中写模型和方法的代码。\n | ",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "### Component class",
"translation": "### 组件类",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, you create a component class.",
"translation": "在Angular中,我们写组件类。",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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)部分。\n ",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "### Dependency injection",
"translation": "### 依赖注入",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "### Dependency injection",
"translation": "### 依赖注入",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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)部分。\n ",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "## Style sheets",
"translation": "## 样式表",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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`标签来为应用程序定义样式。\n ",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "### Link tag",
"translation": "### Link标签",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "In Angular, you can continue to use the link tag to define the styles for your application in the `index.html` file.\n But now you can also encapsulate styles for your components.",
"translation": "在Angular2中,我们可以继续在`index.html`中使用link标签来为应用程序定义样式。\n 但是也能在组件中封装样式。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/ajs-quick-reference.md"
},
{
"original": "### StyleUrls\n 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/content-1/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/content-1/guide/ajs-quick-reference.md"
},
{
"original": "# Animations",
"translation": "# 动画",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/animations.md"
},
{
"original": "动画是现代Web应用设计中一个很重要的方面。我们希望用户界面能在不同的状态之间更平滑的转场。如果需要,还可以用适当的动画来吸引注意力。\n设计良好的动画不但会让UI更有趣,还会让它更容易使用。",
"translation": "## Overview\n## 概述",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "For other browsers, a polyfill is required. Grab\n[`web-animations.min.js` from GitHub](https://github.com/web-animations/web-animations-js) and\nadd it to your page.",
"translation": "至于其它浏览器,就需要一个填充库(polyfill)了。你可以[从这里获取`web-animations.min.js`](https://github.com/web-animations/web-animations-js),并把它加入你的页面中。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "The examples in this page are available as a
.",
"translation": "本章中引用的这个例子可以到
去体验。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "## Transitioning between two states",
"translation": "## 快速起步范例:在两个状态间转场",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/animations.md"
},
{
"original": "Animations can be defined inside `@Component` metadata.",
"translation": "动画会被定义在`@Component`元数据中。",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/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/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "## States and transitions",
"translation": "## 状态与转场",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "Angular animations are defined as logical **states** and **transitions**\nbetween states.",
"translation": "Angular动画是由**状态**和**状态之间的转场效果**所定义的。",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/animations.md"
},
{
"original": "We can define *styles* for each animation state:",
"translation": "我们可以为每个动画状态定义了*一组样式*:",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/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/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "### The wildcard state `*`",
"translation": "### `*`(通配符)状态",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "* The `* => *` transition applies when *any* change between two states takes place.",
"translation": "当在*任意*两个状态之间切换时,`* => *`转场都会生效。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "### The `void` state",
"translation": "### `void`状态",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "The wildcard state `*` also matches `void`.",
"translation": "`*`通配符状态也能匹配`void`。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "## Example: Entering and leaving",
"translation": "## 例子:进场与离场",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/animations.md"
},
{
"original": "* Enter: `void => *`",
"translation": "进场:`void => *`",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "* Leave: `* => void`",
"translation": "离场:`* => void`",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "These two common animations have their own aliases:",
"translation": "这两个常见的动画有自己的别名:",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "## Example: Entering and leaving from different states",
"translation": "## 范例:从不同的状态下进场和离场",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/animations.md"
},
{
"original": "* Inactive hero enter: `void => inactive`",
"translation": "非激活英雄进场:`void => inactive`",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "* Active hero enter: `void => active`",
"translation": "激活英雄进场:`void => active`",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "* Inactive hero leave: `inactive => void`",
"translation": "非激活英雄离场:`inactive => void`",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "* Active hero leave: `active => void`",
"translation": "激活英雄离场:`active => void`",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "This gives you fine-grained control over each transition:",
"translation": "现在就对每一种转场都有了细粒度的控制:",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "## Animatable properties and units",
"translation": "## 可动的(Animatable)属性与单位",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "* `50` is the same as saying `'50px'`",
"translation": "`50`相当于`'50px'`",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "## Automatic property calculation",
"translation": "## 自动属性值计算",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "## Animation timing",
"translation": "## 动画时间线",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/animations.md"
},
{
"original": "### Duration",
"translation": "### 持续时间",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/animations.md"
},
{
"original": "* As a plain number, in milliseconds: `100`",
"translation": "作为一个普通数字,以毫秒为单位,如:`100`",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "* In a string, as milliseconds: `'100ms'`",
"translation": "作为一个字符串,以毫秒为单位,如:`'100ms'`",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "* In a string, as seconds: `'0.1s'`",
"translation": "作为一个字符串,以秒为单位,如:`'0.1s'`",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "### Delay",
"translation": "### 延迟",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "### Easing",
"translation": "### 缓动函数",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "### Example",
"translation": "### 例子",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/animations.md"
},
{
"original": "## Multi-step animations with keyframes",
"translation": "## 基于关键帧(Keyframes)的多阶段动画",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "This example adds some \"bounce\" to the enter and leave animations with\nkeyframes:",
"translation": "在这个例子中,我们使用关键帧来为进场和离场动画添加一些“反弹效果”:",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "## Parallel animation groups",
"translation": "## 并行动画组(Group)",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "其中一个动画组对元素的`transform`和`width`做动画,另一个组则对`opacity`做动画。",
"translation": "## Animation callbacks\n## 动画回调",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/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/content-1/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/content-1/guide/animations.md"
},
{
"original": "Those callbacks will fire whether or not an animation is picked up.",
"translation": "无论动画是否实际执行过,那些回调都会触发。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/animations.md"
},
{
"original": "# Ahead-of-Time Compilation",
"translation": "# 预 (AoT) 编译器",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "This cookbook describes how to radically improve performance by compiling _ahead-of-time_ (AOT)\nduring a build process.",
"translation": "本章描述了如何通过在构建期间使用预编译(AOT编译)技术来根本性的提高性能。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "## Overview",
"translation": "## 概览",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "An Angular application consists largely of components and their HTML templates.\nBefore the browser can render the application,\nthe components and templates must be converted to executable JavaScript by the _Angular compiler_.",
"translation": "Angular应用主要包含组件和它们的HTML模板。\n在浏览器可以渲染应用之前,组件和模板必须要被**Angular编译器**转换为可以执行的JavaScript。",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/aot-compiler.md"
},
{
"original": "You can compile the app in the browser, at runtime, as the application loads, using the **_just-in-time_ (JIT) compiler**.\nThis is the standard development approach shown throughout the documentation.\nIt's great but it has shortcomings.",
"translation": "你可以在浏览器中使用*即时编译器*(Just-in-Time - JIT)在运行期间编译该应用,也就是在应用加载时。\n这是本文档中展示过的标准开发方式。\n它很不错,但是有自己的缺点。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "JIT compilation incurs a runtime performance penalty.\nViews take longer to render because of the in-browser compilation step.\nThe application is bigger because it includes the Angular compiler\nand a lot of library code that the application won't actually need.\nBigger apps take longer to transmit and are slower to load.",
"translation": "JIT编译导致运行期间的性能损耗。\n由于需要在浏览器中执行这个编译过程,视图需要花更长时间才能渲染出来。\n由于应用包含了Angular编译器以及大量实际上并不需要的库代码,所以文件体积也会更大。\n更大的应用需要更长的时间进行传输,加载也更慢。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Compilation can uncover many component-template binding errors.\nJIT compilation discovers them at runtime, which is late in the process.",
"translation": "编译可以发现一些组件模板绑定错误。JIT编译在运行时才揭露它们,那样有点太晚了。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "The **_ahead-of-time_ (AOT) compiler** can catch template errors early and improve performance\nby compiling at build time.",
"translation": "而**预编译**(AOT)会在构建时编译,这样可以在早期截获模板错误,提高应用性能。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "{@a aot-jit}",
"translation": "## _Ahead-of-time_ (AOT) vs _just-in-time_ (JIT)\n## 预编译(AOT) vs 即时编译(JIT)",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "There is actually only one Angular compiler. The difference between AOT and JIT is a matter of timing and tooling.\nWith AOT, the compiler runs once at build time using one set of libraries;\nwith JIT it runs every time for every user at runtime using a different set of libraries.",
"translation": "事实上只有一个Angular编译器,AOT和JIT之间的差别仅仅在于编译的时机和所用的工具。\n使用AOT,编译器仅仅使用一组库在构建期间运行一次;使用JIT,编译器在每个用户的每次运行期间都要用不同的库运行一次。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "## Why do AOT compilation?",
"translation": "## 为什么需要AOT编译?",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "*Faster rendering*",
"translation": "**渲染得更快**",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/aot-compiler.md"
},
{
"original": "*Fewer asynchronous requests*",
"translation": "**需要的异步请求更少**",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/aot-compiler.md"
},
{
"original": "*Smaller Angular framework download size*",
"translation": "**需要下载的Angular框架体积更小**",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/aot-compiler.md"
},
{
"original": "*Detect template errors earlier*",
"translation": "**提早检测模板错误**",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/aot-compiler.md"
},
{
"original": "*Better security*",
"translation": "**更安全**",
"sourceFile": "/Users/twer/private/GDE/content-1/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/content-1/guide/aot-compiler.md"
},
{
"original": "## Compile with AOT",
"translation": "## 用AOT进行编译",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Preparing for offline compilation takes a few simple steps.\nTake the
Setup as a starting point.\nA few minor changes to the lone `app.component` lead to these two class and HTML files:",
"translation": "AOT编译需要一些简单的准备步骤。我们先从
搭建本地开发环境开始。\n只要单独对`app.component`文件的类文件和HTML文件做少量修改就可以了。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Install a few new npm dependencies with the following command:",
"translation": "用下列命令安装少量新的npm依赖:",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "You will run the `ngc` compiler provided in the `@angular/compiler-cli` npm package\ninstead of the TypeScript compiler (`tsc`).",
"translation": "你要用`@angular/compiler-cli`包中提供的`ngc`编译器来代替TypeScript编译器(`tsc`)。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "`ngc` is a drop-in replacement for `tsc` and is configured much the same way.",
"translation": "`ngc`是一个`tsc`的高仿替代品,它们的配置方式几乎完全一样。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "`ngc` requires its own `tsconfig.json` with AOT-oriented settings.\nCopy the original `src/tsconfig.json` to a file called `tsconfig-aot.json` on the project root,\nthen modify it as follows.",
"translation": "`ngc`需要自己的带有AOT专用设置的`tsconfig.json`。\n把原始的`tsconfig.json`拷贝到一个名叫`tsconfig-aot.json`的文件中,然后像这样修改它:",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "The `compilerOptions` section is unchanged except for one property.\n**Set the `module` to `es2015`**.\nThis is important as explained later in the [Tree Shaking](guide/aot-compiler#tree-shaking) section.",
"translation": "`compilerOptions`部分只修改了一个属性:**把`module`设置为`es2015`。\n这一点非常重要,我们会在后面的[摇树优化](guide/aot-compiler#tree-shaking)部分解释为什么。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "What's really new is the `ngc` section at the bottom called `angularCompilerOptions`.\nIts `genDir` property tells the compiler\nto store the compiled output files in a new `aot` folder.",
"translation": "`ngc`区真正新增的内容是底部的`angularCompilerOptions`。\n它的`genDir`属性告诉编译器把编译结果保存在新的`aot`目录下。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "The `\"skipMetadataEmit\" : true` property prevents the compiler from generating metadata files with the compiled application.\nMetadata files are not necessary when targeting TypeScript files, so there is no reason to include them.",
"translation": "`\"skipMetadataEmit\" : true`属性阻止编译器为编译后的应用生成元数据文件。\n当输出成TypeScript文件时,元数据并不是必须的,因此不需要包含它们。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "***Component-relative template URLS***",
"translation": "***相对于组件的模板URL***",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "The AOT compiler requires that `@Component` URLS for external templates and CSS files be _component-relative_.\nThat means that the value of `@Component.templateUrl` is a URL value _relative_ to the component class file.\nFor example, an `'app.component.html'` URL means that the template file is a sibling of its companion `app.component.ts` file.",
"translation": "AOT编译器要求`@Component`中的外部模板和CSS文件的URL是*相对于组件的*。\n这意味着`@Component.templateUrl`的值是一个*相对于*组件类文件的URL值。\n例如,`'app.component.html'` URL表示模板文件与它相应的`app.component.ts`文件放在一起。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "While JIT app URLs are more flexible, stick with _component-relative_ URLs for compatibility with AOT compilation.",
"translation": "而JIT应用的URL更灵活,固定写成*相对于组件的*URL的形式对AOT编译的兼容性也更好。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "***Compiling the application***",
"translation": "*** 编译该应用 ***",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Initiate AOT compilation from the command line using the previously installed `ngc` compiler by executing:",
"translation": "在命令行中执行下列命令,借助刚安装好的`ngc`编译器来启动AOT编译:",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Windows users should surround the `ngc` command in double quotes:",
"translation": "Windows用户应该双引号`ngc`命令:",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "`ngc` expects the `-p` switch to point to a `tsconfig.json` file or a folder containing a `tsconfig.json` file.",
"translation": "`ngc`希望`-p`选项指向一个`tsconfig.json`文件,或者一个包含`tsconfig.json`文件的目录。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "After `ngc` completes, look for a collection of _NgFactory_ files in the `aot` folder.\nThe `aot` folder is the directory specified as `genDir` in `tsconfig-aot.json`.",
"translation": "在`ngc`完成时,会在`aot`目录下看到一组*NgFactory*文件(该目录是在`tsconfig-aot.json`的`genDir`属性中指定的)。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "These factory files are essential to the compiled application.\nEach component factory creates an instance of the component at runtime by combining the original class file\nand a JavaScript representation of the component's template.\nNote that the original component class is still referenced internally by the generated factory.",
"translation": "这些工厂文件对于编译后的应用是必要的。\n每个组件工厂都可以在运行时创建一个组件的实例,其中带有一个原始的类文件和一个用JavaScript表示的组件模板。\n注意,原始的组件类依然是由所生成的这个工厂进行内部引用的。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "The curious can open `aot/app.component.ngfactory.ts` to see the original Angular template syntax\n compiled to TypeScript, its intermediate form.",
"translation": "如果你好奇,可以打开`aot/app.component.ngfactory.ts`来看看原始Angular模板语法被编译成TypeScript时的中间结果。JIT compilation generates these same _NgFactories_ in memory where they are largely invisible.\nAOT compilation reveals them as separate, physical files.",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "如果你好奇,可以打开`aot/app.component.ngfactory.ts`来看看原始Angular模板语法被编译成TypeScript时的中间结果。JIT compilation generates these same _NgFactories_ in memory where they are largely invisible.\nAOT compilation reveals them as separate, physical files.",
"translation": "JIT编译器在内存中同样会生成这一堆*NgFactory*,但它们大部分是不可见的。\nAOT编译器则会生成在单独的物理文件中。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Do not edit the _NgFactories_! Re-compilation replaces these files and all edits will be lost.",
"translation": "不要编辑这些*NgFactory*!重新编译时会替换这些文件,你做的所有修改都会丢失。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "## Bootstrap",
"translation": "## 引导",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "The AOT approach changes application bootstrapping.",
"translation": "AOT也改变了应用的引导方式。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Instead of bootstrapping `AppModule`, you bootstrap the application with the generated module factory, `AppModuleNgFactory`.",
"translation": "引导的方式从引导`AppModule`改成了引导生成的模块工厂:`AppModuleNgFactory`。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Make a copy of `main.ts` and name it `main-jit.ts`.\nThis is the JIT version; set it aside as you may need it [later](guide/aot-compiler#run-jit \"Running with JIT\").",
"translation": "复制一份`main.ts`并把它改名为`main-jit.ts`。\n这就是JIT版本,先把它放在一边,我们[稍后](guide/aot-compiler#run-jit \"Running with JIT\")会用到它。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Open `main.ts` and convert it to AOT compilation.\nSwitch from the `platformBrowserDynamic.bootstrap` used in JIT compilation to\n`platformBrowser().bootstrapModuleFactory` and pass in the AOT-generated `AppModuleNgFactory`.",
"translation": "打开`main.ts`,并把它改成AOT编译。\n从`platformBrowserDynamic.bootstrap`改成使用`platformBrowser().bootstrapModuleFactory`并把`AppModuleNgFactory`的AOT编译结果传给它。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Here is AOT bootstrap in `main.ts` next to the original JIT version:",
"translation": "这里是AOT版本`main.ts`中的引导过程,下一个是你所熟悉的JIT版本。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Be sure to [recompile](guide/aot-compiler#compile) with `ngc`!",
"translation": "确保用`ngc`进行[重新编译](guide/aot-compiler#compile)!",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "## Tree shaking",
"translation": "## 摇树优化(Tree shaking)",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "AOT compilation sets the stage for further optimization through a process called _tree shaking_.\nA tree shaker walks the dependency graph, top to bottom, and _shakes out_ unused code like\ndead leaves in a tree.",
"translation": "AOT编译为接下来通过一个叫做*摇树优化*的过程做好了准备。\n摇树优化器从上到下遍历依赖图谱,并且*摇掉*用不到的代码,这些代码就像是圣诞树中那些死掉的松针一样。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Tree shaking can greatly reduce the downloaded size of the application \nby removing unused portions of both source and library code. \nIn fact, most of the reduction in small apps comes from removing unreferenced Angular features.",
"translation": "通过移除源码和库代码中用不到的部分,摇树优化可以大幅缩减应用的下载体积。\n事实上,在小型应用中大部分的缩减都是因为筛掉了那些没用到的Angular特性。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "For example, this demo application doesn't use anything from the `@angular/forms` library.\nThere is no reason to download forms-related Angular code and tree shaking ensures that you don't.",
"translation": "例如,这个演示程序中没有用到`@angular/forms`库中的任何东西,那么也就没有理由去下载这些与表单有关的Angular代码了。摇树优化可以帮你确保这一点。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Tree shaking and AOT compilation are separate steps.\nTree shaking can only target JavaScript code.\nAOT compilation converts more of the application to JavaScript,\nwhich in turn makes more of the application \"tree shakable\".",
"translation": "摇树优化和AOT编译是单独的步骤。\n摇树优化仅仅针对JavaScript代码。\nAOT编译会把应用中的大部分都转换成JavaScript,这种转换会让应用更容易被“摇树优化”。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "### Rollup",
"translation": "### Rollup 工具",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "This cookbook illustrates a tree shaking utility called _Rollup_.",
"translation": "这个烹饪宝典中用来示范的摇树优化工具是*Rollup*。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Rollup statically analyzes the application by following the trail of `import` and `export` statements.\nIt produces a final code _bundle_ that excludes code that is exported, but never imported.",
"translation": "Rollup会通过跟踪`import`和`export`语句来对本应用进行静态分析。\n它所生成的最终代码*捆*中会排除那些被导出过但又从未被导入的代码。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Rollup can only tree shake `ES2015` modules which have `import` and `export` statements.",
"translation": "Rollup只能对`ES2015`模块摇树,因为那里有`import`和`export`语句。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Recall that `tsconfig-aot.json` is configured to produce `ES2015` modules.\n It's not important that the code itself be written with `ES2015` syntax such as `class` and `const`.\n What matters is that the code uses ES `import` and `export` statements rather than `require` statements.",
"translation": "回忆一下,`tsconfig-aot.json`中曾配置为生成`ES2015`的模块。\n 代码本身是否用到了`ES2015`语法(例如`class`和`const`)并不重要,重要的是这些代码使用的应该是`import`和`export`语句,而不是`require`语句。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "In the terminal window, install the Rollup dependencies with this command:",
"translation": "通过下列命令安装Rollup依赖:",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Next, create a configuration file (`rollup-config.js`)\nin the project root directory to tell Rollup how to process the application.\nThe cookbook configuration file looks like this.",
"translation": "接下来,在项目根目录新建一个配置文件(`rollup-config.js`),来告诉Rollup如何处理应用。\n本烹饪书配置文件是这样的:",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "This config file tells Rollup that the app entry point is `src/app/main.js` .\nThe `dest` attribute tells Rollup to create a bundle called `build.js` in the `dist` folder.\nIt overrides the default `onwarn` method in order to skip annoying messages about the AOT compiler's use of the `this` keyword.",
"translation": "这个配置文件告诉Rollup,该应用的入口点是`app/main.js`。\n`dest`属性告诉Rollup要在`dist`目录下创建一个名叫`build.js`的捆文件。\n它覆盖了默认的`onwarn`方法,以便忽略由于AOT编译器使用`this`关键字导致的噪音消息。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "The next section covers the plugins in more depth.",
"translation": "下一节我们将深入讲解插件。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "### Rollup Plugins",
"translation": "### Rollup插件",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Optional plugins filter and transform the Rollup inputs and output.",
"translation": "这些可选插件过滤并转换Rollup的输入和输出。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "*RxJS*",
"translation": "*RxJS* 库",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Rollup expects application source code to use `ES2015` modules. \nNot all external dependencies are published as `ES2015` modules.\nIn fact, most are not. Many of them are published as _CommonJS_ modules.",
"translation": "Rollup期望应用的源码使用`ES2015`模块。\n但并不是所有外部依赖都发布成了`ES2015`模块。\n事实上,大多数都不是。它们大多数都发布成了*CommonJS*模块。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "The _RxJs_ Observable library is an essential Angular dependency published as an ES5 JavaScript _CommonJS_ module.",
"translation": "可观察对象库*RxJS*是Angular所依赖的基础之一,它就是发布成了ES5 JavaScript的*CommonJS*模块。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Luckily, there is a Rollup plugin that modifies _RxJs_\nto use the ES `import` and `export` statements that Rollup requires.\nRollup then preserves the parts of `RxJS` referenced by the application\nin the final bundle. Using it is straigthforward. Add the following to\nthe `plugins` array in `rollup-config.js`:",
"translation": "幸运的是,有一个Rollup插件,它会修改*RxJS*,以使用Rollup所需的ES`import`和`export`语句。\n然后Rollup就可以把该应用中用到的那部分`RxJS`代码留在“捆”文件中了。\n它的用法很简单。把下列代码添加到`rollup-config.js`的`plugins`数组中:",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "*Minification*",
"translation": "*最小化*",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Rollup tree shaking reduces code size considerably. Minification makes it smaller still.\nThis cookbook relies on the _uglify_ Rollup plugin to minify and mangle the code.\nAdd the following to the `plugins` array:",
"translation": "Rollup做摇树优化时会大幅减小代码体积。最小化过程则会让它更小。\n本烹饪宝典依赖于Rollup插件*uglify*来最小化并混淆代码。\n把下列代码添加到`plugins`数组中:",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "In a production setting, you would also enable gzip on the web server to compress\n the code into an even smaller package going over the wire.",
"translation": "在生产环境中,我们还应该打开Web服务器的gzip特性来把代码压缩得更小。",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "### Run Rollup",
"translation": "### 运行Rollup",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Execute the Rollup process with this command:",
"translation": "通过下列命令执行Rollup过程:",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Windows users should surround the `rollup` command in double quotes:",
"translation": "Windows用户要把`rollup`命令放进双引号中:",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "## Load the bundle",
"translation": "## 加载捆文件",
"sourceFile": "/Users/twer/private/GDE/content-1/guide/aot-compiler.md"
},
{
"original": "Loading the generated application bundle does not require a module loader like SystemJS.\nRemove the scripts that concern SystemJS.\nInstead, load the bundle file using a single `