From 9a0d3e96332ffabccca50e4edf33d841eace15d5 Mon Sep 17 00:00:00 2001 From: Zhicheng Wang Date: Sun, 21 Oct 2018 17:44:10 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=89=8B=E5=8A=A8=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aio/content/guide/animations.md | 300 ++++++- aio/content/guide/aot-compiler.md | 770 +++++++++++++++--- aio/content/guide/architecture-components.md | 24 +- aio/content/guide/architecture-modules.md | 11 +- aio/content/guide/architecture-next-steps.md | 9 +- aio/content/guide/architecture-services.md | 23 +- aio/content/guide/architecture.md | 9 +- aio/content/guide/attribute-directives.md | 2 +- aio/content/guide/bootstrapping.md | 6 +- .../guide/dependency-injection-in-action.md | 234 ++++-- aio/content/guide/dependency-injection.md | 180 +++- aio/content/guide/deployment.md | 118 +++ aio/content/guide/displaying-data.md | 2 +- aio/content/guide/elements.md | 2 +- aio/content/guide/feature-modules.md | 2 +- aio/content/guide/form-validation.md | 59 ++ aio/content/guide/forms.md | 6 +- aio/content/guide/glossary.md | 88 +- .../hierarchical-dependency-injection.md | 134 ++- aio/content/guide/i18n.md | 51 +- aio/content/guide/lazy-loading-ngmodules.md | 2 +- aio/content/guide/ngmodule-vs-jsmodule.md | 2 +- aio/content/guide/npm-packages.md | 4 +- aio/content/guide/observables.md | 6 +- aio/content/guide/providers.md | 5 +- aio/content/guide/quickstart.md | 120 ++- aio/content/guide/reactive-forms.md | 42 +- aio/content/guide/router.md | 217 +++-- aio/content/guide/service-worker-devops.md | 2 +- .../guide/service-worker-getting-started.md | 10 +- aio/content/guide/service-worker-intro.md | 2 +- aio/content/guide/setup.md | 2 +- aio/content/guide/styleguide.md | 2 +- aio/content/guide/testing.md | 6 +- aio/content/guide/universal.md | 176 +++- aio/content/guide/updating.md | 4 +- aio/content/guide/upgrade.md | 11 +- aio/content/guide/visual-studio-2015.md | 11 +- aio/content/navigation.json | 44 +- aio/content/tutorial/toh-pt0.md | 68 +- aio/content/tutorial/toh-pt3.md | 20 +- aio/content/tutorial/toh-pt5.md | 2 +- aio/content/tutorial/toh-pt6.md | 13 +- aio/yarn.lock | 71 +- packages/common/http/src/module.ts | 4 +- packages/common/src/common_module.ts | 3 +- packages/common/src/pipes/async_pipe.ts | 2 +- packages/common/src/pipes/slice_pipe.ts | 4 +- packages/core/src/linker/template_ref.ts | 9 + .../core/src/linker/view_container_ref.ts | 15 +- .../forms/src/directives/form_interface.ts | 4 +- .../select_control_value_accessor.ts | 8 +- packages/forms/src/directives/validators.ts | 8 +- packages/forms/src/form_providers.ts | 15 +- packages/platform-browser/src/browser.ts | 16 +- packages/router/src/router.ts | 6 +- packages/router/src/router_module.ts | 2 +- 57 files changed, 2435 insertions(+), 533 deletions(-) diff --git a/aio/content/guide/animations.md b/aio/content/guide/animations.md index e266c72f9f..dac0c1663d 100644 --- a/aio/content/guide/animations.md +++ b/aio/content/guide/animations.md @@ -1,147 +1,262 @@ # Introduction to Angular animations +# Angular 动画简介 + Animation provides the illusion of motion: HTML elements change styling over time. Well-designed animations can make your application more fun and easier to use, but they aren't just cosmetic. Animations can improve your app and user experience in a number of ways: +动画用于提供运动的幻觉:HTML 元素随着时间改变样式。精心设计的动画可以让你的应用更有趣,更易用,但它们不仅仅是装饰性的。动画可以通过几种方式改善你的应用和用户体验: + * Without animations, web page transitions can seem abrupt and jarring. + 没有动画,Web 页面的转场就会显得突兀、不协调。 + * Motion greatly enhances the user experience, so animations give users a chance to detect the application's response to their actions. + 运动能极大地提升用户体验,因此动画可以让用户察觉到应用对他们的操作做出了响应。 + * Good animations intuitively call the user's attention to where it is needed. + 良好的动画可以直观的把用户的注意力吸引到要留意的地方。 + Typically, animations involve multiple style *transformations* over time. An HTML element can move, change color, grow or shrink, fade, or slide off the page. These changes can occur simultaneously or sequentially. You can control the timing of each transformation. +典型的动画会涉及多种随时间变化的转换。HTML 元素可以移动、变换颜色、增加或缩小、隐藏或从页面中滑出。 +这些变化可以同时发生或顺序发生。你可以控制每次转换的持续时间。 + Angular's animation system is built on CSS functionality, which means you can animate any property that the browser considers animatable. This includes positions, sizes, transforms, colors, borders, and more. The W3C maintains a list of animatable properties on its [CSS Transitions](https://www.w3.org/TR/css-transitions-1/) page. +Angular 的动画系统是基于 CSS 功能构建的,这意味着你可以 "动" 浏览器认为可动的任何属性。包括位置、大小、变形、颜色、边框等。W3C 在它的 [CSS Transitions(转场)](https://www.w3.org/TR/css-transitions-1/) 页中维护了一个可动属性的列表。 ## About this guide +## 关于本指南 + This guide covers the basic Angular animation features to get you started on adding Angular animations to your project. +本指南覆盖了基本的 Angular 动画特性,让你能开始为你的项目添加 Angular 动画。 + The features described in this guide — and the more advanced features described in the related Angular animations guides — are demonstrated in an example app available as a . +本指南中描述的特性,以及相关的 Angular 动画章节中描述的更多高级特性,都在一个范例 中进行了演示。 + #### Prerequisites +#### 前提条件 + The guide assumes that you're familiar with building basic Angular apps, as described in the following sections: +本指南假设你已经能熟练构建基本的 Angular 应用,也就是下列章节中所讲的那些: + * [Tutorial](tutorial) + + [教程](tutorial) + * [Architecture Overview](guide/architecture) + [架构概览](guide/architecture) ## Getting started +## 快速上手 + The main Angular modules for animations are `@angular/animations` and `@angular/platform-browser`. When you create a new project using the CLI, these dependencies are automatically added to your project. +Angular 主要的动画模块是 `@angular/animations` 和 `@angular/platform-browser`。当你使用 CLI 创建新项目时,这些依赖会自动添加到你的项目中。 + To get started with adding Angular animations to your project, import the animation-specific modules along with standard Angular functionality. +为了把 Angular 动画添加到你的项目中,把这些与动画相关的模块和标准的 Angular 功能一起导入进来。 + ### Step 1: Enabling the animations module +### 步骤一:启用动画模块 + Import `BrowserAnimationsModule`, which introduces the animation capabilities into your Angular root application module. +导入 `BrowserAnimationsModule`,它能把动画能力引入应用的根模块中。 +
**Note:** When you use the CLI to create your app, the root application module `app.module.ts` is placed in the `src/app` folder. + +**注意:**当你使用 CLI 创建应用时,应用的根模块 `app.module.ts` 位于 `src/app` 目录下。 +
### Step 2: Importing animation functions into component files +### 步骤二:把动画功能导入组件文件中 + If you plan to use specific animation functions in component files, import those functions from `@angular/animations`. +如果你准备在组件文件中使用特定的动画函数,请从 `@angular/animations` 中导入这些函数。 +
**Note:** See a [summary of available animation functions](guide/animations#animation-api-summary) at the end of this guide. + +**注意:**参见本章末尾的[可用动画函数汇总表](guide/animations#animation-api-summary)。 +
### Step 3: Adding the animation metadata property +### 步骤三:添加动画的元数据属性 + In the component file, add a metadata property called `animations:` within the `@Component()` decorator. You put the trigger that defines an animation within the `animations` metadata property. +在组件的 `@Component()` 装饰器中,添加一个名叫 `animations:` 的元数据属性。 +你可以把用来定义动画的触发器放进 `animations` 元数据属性中。 + ## Animating a simple transition +## 简单转场动画 + Let's animate a simple transition that changes a single HTML element from one state to another. For example, you can specify that a button displays either **Open** or **Closed** based on the user's last action. When the button is in the `open` state, it's visible and yellow. When it's the `closed` state, it's transparent and green. +我们来做一个简单的转场动作,它把单个 HTML 元素从一个状态变成另一个状态。 +比如,你可以指定按钮根据用户的最后一个动作显示成**Open**或**Closed**状态。当按钮处于 `open` 状态时,它是可见的,并且是黄色的。当它处于 `closed` 状态时,它是透明的,并且是绿色的。 + In HTML, these attributes are set using ordinary CSS styles such as color and opacity. In Angular, use the `style()` function to specify a set of CSS styles for use with animations. You can collect a set of styles in an animation state, and give the state a name, such as `open` or `closed`. +在 HTML 中,这些属性都使用普通的 CSS 样式,比如颜色(color)和透明度(opacity)。在 Angular 中,使用 `style()` 函数来指定一组用作动画的 CSS 样式。 +你可以为动画状态指定一组样式,并为该状态指定一个名字,比如 `open` 或 `closed`。 +
open and closed states
### Animation state and styles +### 动画状态和样式 + Use Angular's `state()` function to define different states to call at the end of each transition. This function takes two arguments: a unique name like `open` or `closed` and a `style()` function. +使用 Angular 的 `state()` 函数来定义不同的状态,供每次转场结束时调用。该函数接受两个参数:一个唯一的名字,比如 `open` 或 `closed` 和一个 `style()` 函数。 + Use the `style()` function to define a set of styles to associate with a given state name. Note that the style attributes must be in [*camelCase*](guide/glossary#case-conventions). +使用 `style()` 函数来定义一组与指定的状态名相关的样式。注意,样式的属性必须是[*小驼峰*](guide/glossary#case-conventions) 格式的。 + Let's see how Angular's `state()` function works with the `style⁣­(⁠)` function to set CSS style attributes. In this code snippet, multiple style attributes are set at the same time for the state. In the `open` state, the button has a height of 200 pixels, an opacity of 1, and a background color of yellow. +我们来看看 Angular 的 `state()` 函数如何与 `style()` 函数联用,来设置 CSS 样式的属性。 +在下面的代码片段中,该状态的多个样式属性都是同时设置的。在 `open` 状态中,该按钮的高度是 200 像素,透明度是 1,背景色是黄色。 + In the `closed` state, shown below, the button has a height of 100 pixels, an opacity of 0.5, and a background color of green. +在 `closed` 状态中,按钮的高度是 100 像素,透明度是 0.5,背景色是绿色。 + ### Transitions and timing +### 转场与时序 + In Angular, you can set multiple styles without any animation. However, without further refinement, the button instantly transforms with no fade, no shrinkage, or other visible indicator that a change is occurring. +在 Angular 中,你可以设置多个样式而不必用动画。不过,如果没有进一步细化,按钮的转换会立即完成 —— 没有渐隐、没有收缩,也没有其它的可视化效果来指出正在发生变化。 + To make the change less abrupt, we need to define an animation *transition* to specify the changes that occur between one state and another over a period of time. The `transition()` function accepts two arguments: the first argument accepts an expression that defines the direction between two transition states, and the second argument accepts an `animate()` function. +要让这些变化不那么突兀,我们需要定义一个动画*转场*来要求这些状态之间的变化在一段时间内发生。`transition()` 接受两个参数:第一个参数接受一个表达式,它定义两个转场状态之间的方向;第二个参数接受一个 `animate()` 函数。 Use the `animate()` function to define the length, delay, and easing of a transition, and to designate the style function for defining styles while transitions are taking place. You can also use the `animate()` function to define the `keyframes()` function for multi-step animations. These definitions are placed in the second argument of the `animate()` function. +使用 `animate()` 函数来定义长度、延迟和缓动效果,并指定一个样式函数,以定义转场过程中的样式。 +你还可以使用 `animate()` 函数来为多步动画定义 `keyframes()` 函数。这些定义放在 `animate()` 函数的第二个参数中。 + #### Animation metadata: duration, delay, and easing +#### 动画元数据:持续时间、延迟和缓动效果 + The `animate()` function (second argument of the transition function) accepts the `timings` and `styles` input parameters. +`animate()` 函数(作为转场函数的第二个参数)可以接受 `timings` 和 `styles` 参数。 + The `timings` parameter takes a string defined in three parts. +`timings` 参数接受一个由三部分组成的字符串。 + >`animate ('duration delay easing')` The first part, `duration`, is required. The duration can be expressed in milliseconds as a simple number without quotes, or in seconds with quotes and a time specifier. For example, a duration of a tenth of a second can be expressed as follows: +第一部分 `duration`(持续时间)是必须的。这个持续时间可以表示成一个不带引号的纯数字(表示毫秒),或一个带引号的有单位的时间(表示秒数)。比如,0.1 秒的持续时间有如下表示方式: + * As a plain number, in milliseconds: `100` + 作为纯数字,毫秒为单位:`100` + * In a string, as milliseconds: `'100ms'` + 作为字符串,毫秒为单位:`'100ms'` + * In a string, as seconds: `'0.1s'` + 作为字符串,秒为单位:`'0.1s'` + The second argument, `delay`, has the same syntax as `duration`. For example: +第二个参数 `delay` 的语法和 `duration` 一样。比如: + * Wait for 100ms and then run for 200ms: `'0.2s 100ms'` + 等待 100 毫秒,然后运行 200 毫秒表示为:`'0.2s 100ms'` + The third argument, `easing`, controls how the animation [accelerates and decelerates](http://easings.net/) during its runtime. For example, `ease-in` causes the animation to begin slowly, and to pick up speed as it progresses. +第三个参数 `easing` 控制动画在运行期间如何进行[加速和减速](http://easings.net/)。比如 `ease-in` 表示动画开始时很慢,然后逐渐加速。 + * Wait for 100ms, run for 200ms. Use a deceleration curve to start out fast and slowly decelerate to a resting point: `'0.2s 100ms ease-out'` + 等待 100 毫秒,运行 200 毫秒。按照减速曲线运动,快速启动并逐渐减速,直到静止:`'0.2s 100ms ease-out'` + * Run for 200ms, with no delay. Use a standard curve to start slow, accelerate in the middle, and then decelerate slowly at the end: `'0.2s ease-in-out'` + 运行 200 毫秒,不等待。按照标准曲线运动,开始很慢,中间加速,最后逐渐减速:`'0.2s ease-in-out'` + * Start immediately, run for 200ms. Use a acceleration curve to start slow and end at full velocity: `'0.2s ease-in'` + 立即开始,运行 200 毫秒。按照加速曲线运动,开始很慢,最后达到全速:`'0.2s ease-in'` +
**Note:** See the Angular Material Design website's topic on [Natural easing curves](https://material.io/design/motion/speed.html#easing) for general information on easing curves. + +**注意:**要了解缓动曲线的更多信息,请参阅 Material Design 网站下的[自然缓动曲线](https://material.io/design/motion/speed.html#easing)主题。 +
This example provides a state transition from `open` to `closed` with a one second transition between states. +下面的例子提供了一个从 `open` 到 `closed` 的持续一秒的状态转场。 + In the code snippet above, the `=>` operator indicates unidirectional transitions, and `<=>` is bidirectional. Within the transition, `animate()` specifies how long the transition takes. In this case, the state change from `open` to `closed` takes one second, expressed here as `1s`. +在上面的代码片段中,`=>` 操作符表示单向转场,而 `<=>` 表示双向转场。在转场过程中,`animate()` 指定了转场需要花费的时间。在这里,从 `open` 到 `closed` 状态的转换要花费 1 秒中,表示成 `1s`。 + This example adds a state transition from the `closed` state to the `open` state with a 0.5 second transition animation arc. +下面的例子添加了一个从 `closed` 到 `open` 的状态转场,转场动画持续 0.5 秒。 + @@ -150,23 +265,42 @@ region="transition2"> **Note:** Some additional notes on using styles within `state` and `transition` functions. +**注意:**在 `state` 和 `transition` 函数中使用样式时有一些需要注意的地方。 + * Use `state()` to define styles that are applied at the end of each transition, they persist after the animation has completed. + 请用 `state()` 来定义那些在每个转场结束时样式,这些样式在动画结束时会保留。 + * Use `transition()` to define intermediate styles, which create the illusion of motion during the animation. + 使用 `transition()` 来定义那些中间样式,以便在动画过程中产生运动的错觉。 + * When animations are disabled, `transition()` styles can be skipped, but `state()` styles can't. + 当禁用了动画时,也会忽略 `transition()` 中的样式,但 `state()` 中的样式不会。 + * You can include multiple state pairs within the same `transition()` argument:
`transition( 'on => off, off => void' )`. + + 你可以在同一个 `transition()` 参数中包含多个状态对:
`transition( 'on => off, off => void' )`。 + ### Triggering the animation +### 触发动画 + An animation requires a *trigger*, so that it knows when to start. The `trigger()` function collects the states and transitions, and gives the animation a name, so that you can attach it to the triggering element in the HTML template. +动画需要*触发器*,以便知道该在何时开始。`trigger()` 函数会把一些状态和转场组合在一起,并为这个动画命名,这样你就可以在 HTML 模板中把它附加到想要触发动画的元素上了。 + The `trigger()` function describes the property name to watch for changes. When a change occurs, the trigger initiates the actions included in its definition. These actions can be transitions or other functions, as we'll see later on. +`trigger()` 函数描述了监听变化时要使用的触发器名称。当这个触发器名称所绑定的值发生了变化时,触发器就会启动它所定义的操作。这些操作可能是转场,也可能是其它功能,我们稍后就会看到。 + In this example, we'll name the trigger `openClose`, and attach it to the `button` element. The trigger describes the open and closed states, and the timings for the two transitions. +在这个例子中,我们将把该触发器命名为 `openClose`,并把它附加到 `button` 元素上。该触发器描述了 `open` 和 `closed` 两个状态,以及两个转场效果的时序。 +
triggering the animation
@@ -174,46 +308,71 @@ In this example, we'll name the trigger `openClose`, and attach it to the `butto
**Note:** Within each `trigger()` function call, an element can only be in one state at any given time. However, it's possible for multiple triggers to be active at once. + +**注意:**在每个 `trigger()` 函数调用中,元素在任意时刻只能处于其中的一个状态。但是,元素可以在同一时刻激活多个触发器。 +
### Defining animations and attaching them to the HTML template +### 定义动画,并把它们附加到 HTML 模板中 + Animations are defined in the metadata of the component that controls the HTML element to be animated. Put the code that defines your animations under the `animations:` property within the `@Component()` decorator. +这些控制 HTML 元素如何运动的动画是在组件的元数据中定义的。请在 `@Component()` 装饰器的 `animations:` 属性下用代码定义你要用的动画。 + When you've defined an animation trigger for a component, you can attach it to an element in that component's template by wrapping the trigger name in brackets and preceding it with an `@` symbol. Then, you can bind the trigger to a template expression using standard Angular property binding syntax as shown below, where `triggerName` is the name of the trigger, and `expression` evaluates to a defined animation state. +为组件定义好这些动画触发器之后,你可以给触发器名称加上 `@` 前缀并包在方括号里,来把它附加到组件模板中的元素上。然后,你可以使用如下所示的标准属性绑定语法,来把这个触发器绑定到模板表达式上。这里的 `triggerName` 就是触发器的名称,而 `expression` 的求值结果是前面定义过的动画状态之一。 + ```
...
; ``` The animation is executed or triggered when the expression value changes to a new state. +当该表达式的值变成了新的状态时,动画就会执行或者叫触发。 + The following code snippet binds the trigger to the value of the `isOpen` property. +下列代码片段把该触发器绑定到了 `isOpen` 属性的值上。 + In this example, when the `isOpen` expression evaluates to a defined state of `open` or `closed`, it notifies the trigger `openClose` of a state change. Then it's up to the `openClose` code to handle the state change and kick off a state change animation. +在这个例子中,当 `isOpen` 表达式求值为一个已定义状态 `open` 或 `closed` 时,就会通知 `openClose` 触发器说状态变化了。然后,就由 `openClose` 中的代码来处理状态变更,并启动状态变更动画。 + For elements entering or leaving a page (inserted or removed from the DOM), you can make the animations conditional. For example, use `*ngIf` with the animation trigger in the HTML template. +对于那些进入或离开页面的元素(插入到 DOM 中或从中移除),你可以让动画变成有条件的。例如,在 HTML 模板中可以和 `*ngIf` 一起使用动画触发器。 +
**Note:** In the component file, set the trigger that defines the animations as the value of the `animations:` property in the `@Component()` decorator. +**注意:**在组件文件中,要把用来定义动画的触发器设置为 `@Component()` 装饰器的 `animations:` 属性的值。 + In the HTML template file, use the trigger name to attach the defined animations to the HTML element to be animated. +在 HTML 模板文件中,使用这个触发器的名称来把所定义的这些动画附加到想要添加动画的 HTML 元素上。 +
### Code review +### 代码回顾 + Here are the code files discussed in the transition example. +下面是转场动画范例中讨论过的代码文件。 + ### Summary +### 小节 + You learned to add animation to a simple transition between two states, using `style()` and `state()` along with `animate()` for the timing. +你已经学会了如何在两个状态之间添加简单的转场动画,只要使用 `style()` 和 `state()`,并使用 `animate()` 来定义时序就可以了。 + You can learn about more advanced features in Angular animations under the Animation section, beginning with advanced techniques in [transition and triggers](guide/transition-and-triggers). +你还可以到 "动画" 组下学习更多高级特性,不妨先从[转场与触发器](guide/transition-and-triggers)中讲述的高级技巧开始。 + {@a animation-api-summary} ## Animations API summary +## 动画 API 小节 + The functional API provided by the `@angular/animations` module provides a domain-specific language (DSL) for creating and controlling animations in Angular applications. See the [API reference](api/animations) for a complete listing and syntax details of the core functions and related data structures. +`@angular/animations` 模块提供的这些功能性 API 提供了一种领域特定语言(DSL),用于在 Angular 应用中创建和控制动画效果。到 [API 参考手册](api/animations)中查看完整的列表以及这些核心功能、相关数据结构的详细语法。 + - + - + - + - + - + - + - + - + - + - + - + - + - +
+ Function name + +函数名 + + What it does + +用途 +
trigger()Kicks off the animation and serves as a container for all other animation function calls. HTML template binds to triggerName. Use the first argument to declare a unique trigger name. Uses array syntax. + +Kicks off the animation and serves as a container for all other animation function calls. HTML template binds to triggerName. Use the first argument to declare a unique trigger name. Uses array syntax. + +开始动画,并充当所有其它动画函数的容器。HTML 模板可以绑定到 triggerName。使用第一个参数来声明唯一的触发器名称。要使用数组语法。 + +
style()Defines one or more CSS styles to use in animations. Controls the visual appearance of HTML elements during animations. Uses object syntax. + +Defines one or more CSS styles to use in animations. Controls the visual appearance of HTML elements during animations. Uses object syntax. + +定义一个或多个要用于动画中的 CSS 样式。用于在动画期间控制 HTML 元素的视觉外观。要使用对象语法。 + +
state()Creates a named set of CSS styles that should be applied on successful transition to a given state. The state can then be referenced by name within other animation functions. + +Creates a named set of CSS styles that should be applied on successful transition to a given state. The state can then be referenced by name within other animation functions. + +创建一组有名字的 CSS 样式,它会在成功转换到指定的状态时应用到元素上。该状态可以在其它动画函数中通过名字进行引用。 + +
animate()Specifies the timing information for a transition. Optional values for delay and easing. Can contain style() calls within. + +Specifies the timing information for a transition. Optional values for delay and easing. Can contain style() calls within. + +指定转场的时序信息。delayeasing 是可选值。其中可以包含 style() 调用。 + +
transition()Defines the animation sequence between two named states. Uses array syntax. + +Defines the animation sequence between two named states. Uses array syntax. + +定义两个命名状态之间的动画序列。使用数组语法。 + +
keyframes()Allows a sequential change between styles within a specified time interval. Use within animate(). Can include multiple style() calls within each keyframe(). Uses array syntax. + +Allows a sequential change between styles within a specified time interval. Use within animate(). Can include multiple style() calls within each keyframe(). Uses array syntax. + +允许以特定的时间间隔对样式进行顺序更改。用于 animate() 中。每个 keyframe() 中都可以包含多个 style() 调用。使用数组语法。 + +
group()Specifies a group of animation steps (inner animations) to be run in parallel. Animation continues only after all inner animation steps have completed. Used within sequence() or transition(). + +Specifies a group of animation steps (inner animations) to be run in parallel. Animation continues only after all inner animation steps have completed. Used within sequence() or transition(). + +指定要并行运行的一组动画步骤(内部动画)。 +该动画只有当所有内部动画步骤都完成之后才会继续。用于 sequence()transition() 中。 + +
query()Use to find one or more inner HTML elements within the current element. + +Use to find one or more inner HTML elements within the current element. + +用于找出当前元素中的一个或多个内部 HTML 元素。 + +
sequence()Specifies a list of animation steps that are run sequentially, one by one. + +Specifies a list of animation steps that are run sequentially, one by one. + +指定一个动画步骤列表,它们会逐个顺序执行。 + +
stagger()Staggers the starting time for animations for multiple elements. + +Staggers the starting time for animations for multiple elements. + +交错安排多元素动画的开始时间。 + +
animation()Produces a reusable animation that can be invoked from elsewhere. Used together with useAnimation(). + +Produces a reusable animation that can be invoked from elsewhere. Used together with useAnimation(). + +生成可在其它地方调用的可重用动画。与 useAnimation() 一起使用。 + +
useAnimation()Activates a reusable animation. Used with animation(). + +Activates a reusable animation. Used with animation(). + +激活一个可复用动画。和 animation() 一起使用。 + +
animateChild()Allows animations on child components to be run within the same timeframe as the parent. + +Allows animations on child components to be run within the same timeframe as the parent. + +允许子组件上的动画和父组件在同一个时间范围(timeframe)内执行。 + +
## More on Angular animations +## 关于 Angular 动画的更多知识 + You may also be interested in the following: +你可能还对下列内容感兴趣: + * [Transition and triggers](guide/transition-and-triggers) + + [转场与触发器](guide/transition-and-triggers) + * [Complex animation sequences](guide/complex-animation-sequences) + + [复杂动画序列](guide/complex-animation-sequences) + * [Reusable animations](guide/reusable-animations) + + [可复用动画](guide/reusable-animations) + * [Route transition animations](guide/route-animations) + [路由转场动画](guide/route-animations) +
Check out this full animation [demo](http://animationsftw.in/#/) with accompanying [presentation](https://www.youtube.com/watch?v=JhNo3Wvj6UQ&feature=youtu.be&t=2h47m53s), shown at the AngularConnect conference in November 2017. + +到这个 [Demo](http://animationsftw.in/#/) 中查看 2017 年 11 月的 AngularConnect 大会上完整的动画及其[演示](https://www.youtube.com/watch?v=JhNo3Wvj6UQ&feature=youtu.be&t=2h47m53s)。 +
diff --git a/aio/content/guide/aot-compiler.md b/aio/content/guide/aot-compiler.md index 583ae7398c..2f854b3639 100644 --- a/aio/content/guide/aot-compiler.md +++ b/aio/content/guide/aot-compiler.md @@ -4,10 +4,17 @@ An Angular application consists mainly of components and their HTML templates. Because the components and templates provided by Angular cannot be understood by the browser directly, Angular applications require a compilation process before they can run in a browser. +Angular 应用主要由组件及其 HTML 模板组成。由于浏览器无法直接理解 Angular 所提供的组件和模板,因此 Angular 应用程序需要先进行编译才能在浏览器中运行。 + 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. Compiling your application during the build process provides a faster rendering in the browser. +在浏览器下载和运行代码*之前*的编译阶段,Angular 预先(AOT)编译器会先把你的 Angular HTML 和 TypeScript 代码转换成高效的 JavaScript 代码。 +在构建期间编译应用可以让浏览器中的渲染更快速。 + This guide explains how to specify metadata and apply available compiler options to compile your applications efficiently using the AOT compiler. +本指南中解释了如何指定元数据,并通过一些编译器选项来借助 AOT 编译器来更有效的编译应用。 +
Watch compiler author Tobias Bosch explain the Angular compiler at AngularConnect 2016. @@ -20,16 +27,23 @@ This guide explains how to specify metadata and apply available compiler options ## Angular compilation +## Angular 中的编译 + Angular offers two ways to compile your application: +Angular 提供了两种方式来编译你的应用: + 1. **_Just-in-Time_ (JIT)**, which compiles your app in the browser at runtime. + + ***即时编译* (JIT)**,它会在运行期间在浏览器中编译你的应用。 + 1. **_Ahead-of-Time_ (AOT)**, which compiles your app at build time. **预先(AOT)编译**,它会在构建时编译你的应用。 JIT compilation is the default when you run the [`ng build`](cli/build) (build only) or [`ng serve`](cli/serve) (build and serve locally) CLI commands: -当你运行 *`build`* 或 *`serve`* 这两个 CLI 命令时 JIT 编译是默认选项: +当你运行 [`ng build`](cli/build)(仅编译)或 [`ng serve`](cli/serve)(编译并启动本地服务器) 这两个 CLI 命令时 JIT 编译是默认选项: ng build @@ -40,7 +54,7 @@ JIT compilation is the default when you run the [`ng build`](cli/build) (build o For AOT compilation, include the `--aot` option with the `ng build` or `ng serve` command: -要进行 AOT 编译只要给这两个 CLI 命令添加 `--aot` 标志就行了: +要进行 AOT 编译只要给 `ng build` 或 `ng serve` 命令添加 `--aot` 标志就行了: ng build --aot @@ -51,11 +65,11 @@ For AOT compilation, include the `--aot` option with the `ng build` or `ng serve The `ng build` command with the `--prod` meta-flag (`ng build --prod`) compiles with AOT by default. -`--prod` 标志也会默认使用 AOT 编译。 +带有 `--prod` 标志的 `ng build` 命令 (`ng build --prod`) 会默认使用 AOT 编译。 See the [CLI command reference](cli) and [Building and serving Angular apps](guide/build) for more information. -要了解更多,请参见[CLI 文档](https://github.com/angular/angular-cli/wiki),特别是[`build` 这个主题](https://github.com/angular/angular-cli/wiki/build)。 +要了解更多,请参见[CLI 文档](cli),和 [构建与启动开发服务器](guide/build)。
@@ -82,7 +96,7 @@ The browser loads executable code so it can render the application immediately, The compiler _inlines_ external HTML templates and CSS style sheets within the application JavaScript, eliminating separate ajax requests for those source files. -编译器把外部 HTML 模板和 CSS 样式表内联到了该应用的 JavaScript 中。 +编译器把外部 HTML 模板和 CSS 样式表*内联*到了该应用的 JavaScript 中。 消除了用来下载那些源文件的 Ajax 请求。 *Smaller Angular framework download size* @@ -112,26 +126,40 @@ AOT compiles HTML templates and components into JavaScript files long before the With no templates to read and no risky client-side HTML or JavaScript evaluation, there are fewer opportunities for injection attacks. +AOT 方式会在发给客户端之前就把 HTML 模板和组件编译成 JavaScript 文件。 +不需要读取模板,也没有客户端组装 HTML 或执行 JavaScript 的危险操作,受到注入类攻击的机会也比较少。 + ## Controlling app compilation +## 控制应用的编译方式 + When you use the Angular AOT compiler, you can control your app compilation in two ways: +当使用 AOT 编译器时,你可以通过两种方式来控制应用的编译方式: + * By providing template compiler options in the `tsconfig.json` file. - For more information, see [Angular template compiler options](#compiler-options). + 在 `tsconfig.json` 文件中提供模板编译选项。 + + For more information, see [Angular template compiler options](#compiler-options). + + 欲知详情,参见 [Angular 模板编译器选项](#compiler-options)。 * By [specifying Angular metadata](#metadata-aot). + 通过[指定 Angular 元数据](#metadata-aot)。 + {@a metadata-aot} ## Specifying Angular metadata -Angular 的 **AOT 编译器**会提取并解释应用中由 Angular 管理的各个部件的**元数据**。 +## 指定 Angular 元数据 Angular metadata tells Angular how to construct instances of your application classes and interact with them at runtime. The Angular **AOT compiler** extracts **metadata** to interpret the parts of the application that Angular is supposed to manage. Angular 的元数据会告诉 Angular 如何创建应用中类的实例以及如何在运行期间与它们交互。 +Angular 的 **AOT 编译器**会把**元数据**提取出来,以告诉 Angular 应该管理应用程序的哪些部分。 You can specify the metadata with **decorators** such as `@Component()` and `@Input()` or implicitly in the constructor declarations of these decorated classes. @@ -231,81 +259,266 @@ Angular 的 [schema.ts](https://github.com/angular/angular/blob/master/packages/ The _collector_ only understands a subset of JavaScript. Define metadata objects with the following limited syntax: +*收集器*只能理解 JavaScript 的一个子集。 +定义元数据对象时要遵循下列语法限制: + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + +
SyntaxExample + + Syntax + + 语法 + + + + Example + + 范例 + +
Literal object {cherry: true, apple: true, mincemeat: false} + + Literal object + + 对象字面量 + + + + {cherry: true, apple: true, mincemeat: false} + +
Literal array ['cherries', 'flour', 'sugar'] + + Literal array + + 数组字面量 + + + + ['cherries', 'flour', 'sugar'] + +
Spread in literal array['apples', 'flour', ...the_rest] + + Spread in literal array + + 展开数组字面量 + + + + ['apples', 'flour', ...the_rest] + +
Callsbake(ingredients) + + Calls + + 函数调用 + + + + bake(ingredients) + +
Newnew Oven() + + New + + 新建对象 + + + + new Oven() + +
Property accesspie.slice + + Property access + + 属性访问 + + + + pie.slice + +
Array indexingredients[0] + + Array index + + 数组索引访问 + + + + ingredients[0] + +
Identity referenceComponent + + Identity reference + + 引用标识符 + + + + Component + +
A template string`pie is ${multiplier} times better than cake` + + A template string + + 模板字符串 + + + + `pie is ${multiplier} times better than cake` + +
Literal stringpi + + Literal string + + 字符串字面量 + + + + pi + +
Literal number3.14153265 + + Literal number + + 数字字面量 + + + + 3.14153265 + +
Literal booleantrue + + Literal boolean + + 逻辑字面量 + + + + true + +
Literal nullnull + + Literal null + + null 字面量 + + + + null + +
Supported prefix operator !cake + + Supported prefix operator + + 受支持的前缀运算符 + + + + !cake + +
Supported binary operator a+b + + Supported binary operator + + 受支持的二元运算符 + + + + a+b + +
Conditional operatora ? b : c + + Conditional operator + + 条件运算符 + + + + a ? b : c + +
Parentheses(a+b) + + Parentheses + + 括号 + + + + (a+b) + +
@@ -515,86 +728,316 @@ The _collector_ reduces this expression to its equivalent _folded_ string: The following table describes which expressions the _collector_ can and cannot fold: +下表中描述了*收集器*可以折叠以及不能折叠哪些表达式: + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + +
SyntaxFoldable + + Syntax + + 语法 + + + + Foldable + + 可折叠? + +
Literal object Yes + + Literal object + + 对象字面量 + + + + Yes + + 是 + +
Literal array Yes + + Literal array + + 数组字面量 + + + + Yes + + 是 + +
Spread in literal arrayno + + Spread in literal array + + 展开数组字面量 + + + + no + + 否 + +
Callsno + + Calls + + 函数调用 + + + + no + + 否 + +
Newno + + New + + 新建对象 + + + + no + + 否 + +
Property accessyes, if target is foldable + + Property access + + 属性访问 + + + + yes, if target is foldable + + 如果目标对象也是可折叠的,则是 + +
Array index yes, if target and index are foldable + + Array index + + 数组索引访问 + + + + yes, if target and index are foldable + + 如果目标数组和索引都是可折叠的,则是 + +
Identity referenceyes, if it is a reference to a local + + Identity reference + + 引用标识符 + + + + yes, if it is a reference to a local + + 如果引用的是局部标识符,则是 + +
A template with no substitutionsyes + + A template with no substitutions + + 没有替换表达式的模板字符串 + + + + yes + + 是 + +
A template with substitutionsyes, if the substitutions are foldable + + A template with substitutions + + 有替换表达式的模板字符串 + + + + yes, if the substitutions are foldable + + 如果替换表达式是可折叠的,则是 + +
Literal stringyes + + Literal string + + 字符串字面量 + + + + yes + + 是 + +
Literal numberyes + + Literal number + + 数字字面量 + + + + yes + + 是 + +
Literal booleanyes + + Literal boolean + + 逻辑字面量 + + + + yes + + 是 + +
Literal nullyes + + Literal null + + null 字面量 + + + + yes + + 是 + +
Supported prefix operator yes, if operand is foldable + + Supported prefix operator + + 受支持的前缀运算符 + + + + yes, if operand is foldable + + 如果操作数是可折叠的,则是 + +
Supported binary operator yes, if both left and right are foldable + + Supported binary operator + + 受支持的二元运算符 + + + + yes, if both left and right are foldable + + 如果左操作数和右操作数都是可折叠的,则是 + +
Conditional operatoryes, if condition is foldable + + Conditional operator + + 条件运算符 + + + + yes, if condition is foldable + + 如果条件是可折叠的,则是 + +
Parenthesesyes, if the expression is foldable + + Parentheses + + 括号 + + + + yes, if the expression is foldable + + 如果表达式是可折叠的,则是 + +
@@ -664,14 +1107,28 @@ The compiler only allows metadata that create instances of the class `InjectionT The compiler only supports metadata for these Angular decorators. +编译器只支持下列 Angular 装饰器中的元数据。 + - - + + @@ -746,7 +1203,7 @@ The compiler only supports metadata for these Angular decorators. -
DecoratorModule + + Decorator + + 装饰器 + + + + Module + + 模块 + +
Attribute@angular/core
+ ### Macro-functions and macro-static methods @@ -822,7 +1279,7 @@ The compiler treats object literals containing the fields `useClass`, `useValue` the compiler doesn't need to know the expression's value—it just needs to be able to generate a reference to the value. 编译器会对含有 `useClass`、`useValue`、`useFactory` 和 `data` 的对象字面量进行特殊处理。 -编译器会把用这些字段之一初始化的表达式转换成一个导出为一个变量,并用它替换该表达式。 +编译器会把用这些字段之一初始化的表达式转换成一个导出的变量,并用它替换该表达式。 这个重写表达式的过程,会消除它们受到的所有限制,因为编译器并不需要知道该表达式的值,它只要能生成对该值的引用就行了。 You might write something like: @@ -946,6 +1403,8 @@ and be wary of new or unusual TypeScript features. _Reference to a local (non-exported) symbol 'symbol name'. Consider exporting the symbol._ +*如果要引用局部(未导出的)符号 'symbol name',请考虑导出它。* + The compiler encountered a referenced to a locally defined symbol that either wasn't exported or wasn't initialized. @@ -1061,6 +1520,8 @@ Prefixing the declaration with `export` merely produces a new error, "[`Only ini _Only initialized variables and constants can be referenced because the value of this variable is needed by the template compiler._ +*只能引用已初始化过的变量和常量,因为模板编译器需要该变量的值。* + The compiler found a reference to an exported variable or static field that wasn't initialized. @@ -1138,6 +1599,8 @@ export class MyComponent {} _Reference to a non-exported class . Consider exporting the class._ +*如果要引用未导出的类 ,请考虑导出它。* + Metadata referenced a class that wasn't exported. @@ -1241,6 +1704,8 @@ export function myStrategy() { ... } _Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function._ +*不支持函数调用。考虑把这个函数或 lambda 表达式替换成一个对已导出函数的引用。* + The compiler does not currently support [function expressions or lambda functions](#function-expression). @@ -1312,6 +1777,8 @@ export function someValueFactory() { _Referencing an exported destructured variable or constant is not supported by the template compiler. Consider simplifying this to avoid destructuring._ +*模板编译器不支持引用导出的解构语法的变量或常量。考虑简化这一点,以避免解构语法。* + The compiler does not support references to variables assigned by [destructuring](https://www.typescriptlang.org/docs/handbook/variable-declarations.html#destructuring). @@ -1535,6 +2002,8 @@ Avoid referring to enums with complicated initializers or computed properties. _Tagged template expressions are not supported in metadata._ +*元数据中不支持带标签函数的模板表达式。* + The compiler encountered a JavaScript ES2015 [tagged template expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) such as, @@ -1633,10 +2102,10 @@ Chuck: After reviewing your PR comment I'm still at a loss. See [comment there]( `templateUrl` instead of `template`, the errors are reported in the HTML file referenced by the `templateUrl` instead of a synthetic file. - 错误信息中汇报的文件名 `my.component.ts.MyComponent.html` 是一个由模板编译器生成出的虚拟文件, + 错误信息中汇报的文件名 `my.component.ts.MyComponent.html` 是一个由模板编译器生成出的合成文件, 用于保存 `MyComponent` 类的模板内容。 编译器永远不会把这个文件写入磁盘。这个例子中,这里的行号和列号都是相对于 `MyComponent` 的 `@Component` 注解中的模板字符串的。 - 如果组件使用 `templateUrl` 来代替 `template`,这些错误就会在 `templateUrl` 引用的 HTML 文件中汇报,而不是这个虚拟文件中。 + 如果组件使用 `templateUrl` 来代替 `template`,这些错误就会在 `templateUrl` 引用的 HTML 文件中汇报,而不是这个合成文件中。 The error location is the beginning of the text node that contains the interpolation expression with the error. If the error is in an attribute binding such as `[value]="person.address.street"`, the error @@ -1798,10 +2267,19 @@ Chuck: After reviewing your PR comment I'm still at a loss. See [comment there]( {@a tsconfig-extends} ## Configuration inheritance with extends + +## 用 `extends` 语法配置继承方式 + Similar to TypeScript Compiler, Angular Compiler also supports `extends` in the `tsconfig.json` on `angularCompilerOptions`. A tsconfig file can inherit configurations from another file using the `extends` property. The `extends` is a top level property parallel to `compilerOptions` and `angularCompilerOptions`. The configuration from the base file are loaded first, then overridden by those in the inheriting config file. Example: + +像 TypeScript 编译器相似,Angular 编译器也支持在 `tsconfig.json` 的 `angularCompilerOptions` 中使用 `extends` 语法。 +tsconfig 文件可以 使用 `extends` 属性从其它文件中继承配置。 +`extends` 位于顶级,和 `compilerOptions`、`angularCompilerOptions` 同级。 +首先加载 base 文件中的配置,然后用当前配置文件中的选项进行覆盖。比如: + ```json { "extends": "../tsconfig.base.json", @@ -1816,13 +2294,21 @@ Similar to TypeScript Compiler, Angular Compiler also supports `extends` in the } } ``` - More information about tsconfig extends can be found in the [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html). + +More information about tsconfig extends can be found in the [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html). + +关于 tsconfig `extends` 语法的更多知识,参见 [TypeScript 手册](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html)。 {@a compiler-options} ## Angular template compiler options +## Angular 模板编译器选项 + The template compiler options are specified as members of the `"angularCompilerOptions"` object in the `tsconfig.json` file. Specify template compiler options along with the options supplied to the TypeScript compiler as shown here: +模板编译器的选项通过 `tsconfig.json` 文件中 `"angularCompilerOptions"` 对象的成员来指定。 +给模板编译器的选项随着给 TypeScript 选项一起提供,如下所示: + ```json { "compilerOptions": { @@ -1839,34 +2325,53 @@ The template compiler options are specified as members of the `"angularCompilerO The following section describes the Angular's template compiler options. +下面的部分会讲解 Angular 模板编译器的选项。 + ### *enableResourceInlining* + This option instructs the compiler to replace the `templateUrl` and `styleUrls` property in all `@Component` decorators with inlined contents in `template` and `styles` properties. When enabled, the `.js` output of `ngc` will have no lazy-loaded `templateUrl` or `styleUrls`. +该选项指示编译器将所有 `@Component` 装饰器中的 `templateUrl` 和 `styleUrls` 属性替换成内联在 `template` 和 `styles` 属性中的常量。 +当启用时,`ngc` 输出的 `.js` 文件中就没有惰性加载的 `templateUrl` 或 `styleUrls`。 + ### *skipMetadataEmit* This option tells the compiler not to produce `.metadata.json` files. The option is `false` by default. +该选项告诉编译器不要生成 `.metadata.json` 文件。默认为 `false`。 + `.metadata.json` files contain information needed by the template compiler from a `.ts` file that is not included in the `.d.ts` file produced by the TypeScript compiler. This information contains, for example, the content of annotations (such as a component's template), which TypeScript emits to the `.js` file but not to the `.d.ts` file. +`.metadata.json` 文件中包含模板编译器需要从 `.ts` 文件中获取的信息,但它没有包含在由 TypeScript 编译器生成的 `.d.ts` 文件中。 +比如,该信息包含注解的内容(比如组件的模板),TypeScript 会把它放进 `.js` 文件里,但不会放进 `.d.ts` 文件里。 + This option should be set to `true` if you are using TypeScript's `--outFile` option, because the metadata files are not valid for this style of TypeScript output. It is not recommended to use `--outFile` with Angular. Use a bundler, such as [webpack](https://webpack.js.org/), instead. +如果你要使用 TypeScript 的 `--outFile` 选项,则该选项应该设置为 `true`,因为 TypeScript 的这种输出形式中没有包含元数据。不建议在 Angular 中使用 `--outFile` 选项。请改用像 [webpack](https://webpack.js.org/) 这样的打包器。 + This option can also be set to `true` when using factory summaries because the factory summaries include a copy of the information that is in the `.metadata.json` file. +当使用工厂摘要(factory summaries)时,该选项也可以设置为 `true`,因为工厂摘要包含了 `.metadata.json` 中那些信息的副本。 + ### *strictMetadataEmit* This option tells the template compiler to report an error to the `.metadata.json` file if `"skipMetadataEmit"` is `false`. This option is `false` by default. This should only be used when `"skipMetadataEmit"` is `false` and `"skipTemplateCodeGen"` is `true`. +该选项告诉模板编译器,,当 `"skipMetadataEmit"` 为 `false` 时,就要向 `.metadata.json` 中报告一个错误。该选项默认为 `false`。只有当 `"skipMetadataEmit"` 为 `false`,而且 `"skipTemplateCodeGen"` 为 `true` 时才应该开启该选项。 + This option is intended to validate the `.metadata.json` files emitted for bundling with an `npm` package. The validation is strict and can emit errors for metadata that would never produce an error when used by the template compiler. You can choose to suppress the error emitted by this option for an exported symbol by including `@dynamic` in the comment documenting the symbol. +该选项是为了验证为生成 `npm` 包而产生的 `.metadata.json` 文件。这种验证是严格的,并且会报告元数据中的错误,以免当模板编译器使用它时再出错。你可以通过在某个导出符号的注释文档中使用 `@dynamic` 注释来暂时防止(suppress)该选项报告错误。 + It is valid for `.metadata.json` files to contain errors. The template compiler reports these errors if the metadata is used to determine the contents of an annotation. The metadata collector cannot predict the symbols that are designed for use in an annotation, so it will preemptively @@ -1875,6 +2380,9 @@ nodes to report an error if these symbols are used. If the client of a library i this until the client uses the symbol. This option allows detecting these errors during the build phase of the library and is used, for example, in producing Angular libraries themselves. +即使 `.metadata.json` 中包含错误,如果该元数据只是用来确定注解的内容,那么它仍然可能是有效的。 +元数据收集器无法预知哪些符号是为了用作注解而设计的,所以它会先在导出符号的元数据中包含这些错误节点。然后,如果模板编译器真的用到了这些符号,它就能使用这个错误节点来报告错误。如果库的使用者想要在注解中使用某个符号,则直到客户代码使用了该符号时,模板编译器才会报告该错误。此选项能让你在库的构建阶段就检测出这类错误,比如,Angular 本身的这些库就是这么干的。 + ### *skipTemplateCodegen* This option tells the compiler to suppress emitting `.ngfactory.js` and `.ngstyle.js` files. When set, @@ -1884,14 +2392,23 @@ template compiler to produce `.metadata.json` files for distribution with an `np avoiding the production of `.ngfactory.js` and `.ngstyle.js` files that cannot be distributed to `npm`. +该选项告诉编译器不要生成 `.ngfactory.js` 和 `.ngstyle.js` 文件。 +如果设置了,则它会关闭大多数模板编译器,并禁止报告对模板的诊断信息。 +该选项可用于指示模板编译器生成 `.metadata.json` 文件,以便作为 `npm` 包进行分发,同时,避免生成那些无法分发到 `npm` 的 `.ngfactory.js` 和 `.ngstyle.js` 文件。 + ### *strictInjectionParameters* When set to `true`, this options tells the compiler to report an error for a parameter supplied whose injection type cannot be determined. When this option is not provided or is `false`, constructor parameters of classes marked with `@Injectable` whose type cannot be resolved will produce a warning. +当设置为 `true` 时,该选项告诉编译器对那些无法确定类型的注入参数报错。 +当不提供该选项或为 `false` 时,对于标记为 `@Injectable` 的类的构造函数中那些无法确定类型的参数将生成一个警告。 + *Note*: It is recommended to change this option explicitly to `true` as this option will default to `true` in the future. +**注意**:建议将此选项显式更改为 `true`,因为此选项将来将会默认为 `true`。 + ### *flatModuleOutFile* When set to `true`, this option tells the template compiler to generate a flat module @@ -1904,6 +2421,9 @@ for symbols exported from the library index. In the generated `.ngfactory.js` fi module index is used to import symbols that includes both the public API from the library index as well as shrowded internal symbols. +如果为 `true`,则该选项告诉模板编译器为指定的文件名生成一个扁平模块索引和相应的扁平模块元数据。当创建打包形式类似于 `@angular/core` 和 `@angular/common` 这样的扁平模块时,请使用该选项。 +使用此选项,只会生成一个 `.metadata.json` 文件,其中包含从库索引中导出的符号所需的全部元数据。在生成的 `.ngfactory.js` 文件中,扁平模块索引用于导入所有符号,包括库索引中的公共 API,和那些受限的内部符号。 + By default the `.ts` file supplied in the `files` field is assumed to be the library index. If more than one `.ts` file is specified, `libraryIndex` is used to select the file to use. If more than one `.ts` file is supplied without a `libraryIndex`, an error is produced. A flat module @@ -1915,6 +2435,10 @@ example `"index.js"`, which produces `index.d.ts` and `index.metadata.json` fil library's `package.json`'s `module` field would be `"index.js"` and the `typings` field would be `"index.d.ts"`. +默认情况下,`files` 字段中提供的 `.ts` 文件会被当做库索引。如果指定了多个 `.ts` 文件,则使用 `libraryIndex` 来选择要使用的索引文件。如果提供了多个 `.ts` 文件但没有指定 `libraryIndex`,就会产生错误。 +编译器会用 `flatModuleOutFile` 所指定的名称在与库索引的 `.d.ts` 文件相同的位置创建平面模块索引的 `.d.ts` 和 `.js` 文件。比如,如果库使用 `public_api.ts` 文件作为模块的库索引,则 `tsconfig.json` 的 `files` 字段应该是 `["public_api.ts"]`。 +`flatModuleOutFile`。然后还可以将 `flatModuleOutFile` 选项设置为 `index.js`,它将会生成 `index.d.ts` 和 `index.metadata.json` 文件。这个库的 `package.json` 的 `module` 字段将会是 `"inex.js"`,而 `typings` 字段将会是 `"index.d.ts"`。 + ### *flatModuleId* This option specifies the preferred module id to use for importing a flat module. @@ -1923,51 +2447,91 @@ from the flat module. This is only meaningful when `flatModuleOutFile` is also supplied. Otherwise the compiler ignores this option. +该选项可以指定用于导入平面模块的首选模块 ID。从平面模块中导入符号时,模板编译器所生成的引用将使用此模块名称。只有在同时提供了 `flatModuleOutFile` 选项时,该选项才有意义,否则编译器会忽略它。 + ### *generateCodeForLibraries* This option tells the template compiler to generate factory files (`.ngfactory.js` and `.ngstyle.js`) for `.d.ts` files with a corresponding `.metadata.json` file. This option defaults to `true`. When this option is `false`, factory files are generated only for `.ts` files. +该选项告诉模板编译器,为 `.d.ts` 文件生成与 `.metadata.json` 对应的工厂文件(`.ngfactory.js` 和 `.ngstyle.js`)。该选项默认为 `true`。如果为 `false`,则只会为 `.ts` 文件生成工厂文件。 + This option should be set to `false` when using factory summaries. +当使用工厂摘要(factory summaries)时,该选项应该设置为 `false`。 + ### *fullTemplateTypeCheck* This option tells the compiler to enable the [binding expression validation](#binding-expression-validation) phase of the template compiler which uses TypeScript to validate binding expressions. +该选项告诉编译器,为模板编译器开启[绑定表达式校验](#binding-expression-validation)阶段,它使用 TypeScript 来验证各个绑定表达式。 + This option is `false` by default. +该选项默认为 `false`。 + *Note*: It is recommended to set this to `true` because this option will default to `true` in the future. +*注意*:建议把它设置为 `true`,因为该选项将来会默认为 `true`。 + ### *annotateForClosureCompiler* This option tells the compiler to use [Tsickle](https://github.com/angular/tsickle) to annotate the emitted JavaScript with [JSDoc](http://usejsdoc.org/) comments needed by the [Closure Compiler](https://github.com/google/closure-compiler). This option defaults to `false`. +该选项会告诉编译器使用 [Tsickle](https://github.com/angular/tsickle) 来为所生成的 JavaScript 文件添加 [JSDoc](http://usejsdoc.org/) 注释,供 [Closure Compiler](https://github.com/google/closure-compiler) 使用。该选项默认为 `false`。 + ### *annotationsAs* Use this option to modify how the Angular specific annotations are emitted to improve tree-shaking. Non-Angular annotations and decorators are unaffected. Default is `static fields`. +使用该选项可以修改 Angular 特有的注解的生成方式,以改善摇树优化。对非 Angular 的注解和装饰器无效。默认为 `static fields` + - - + + - + - +
ValueDescription + + Value + + 值 + + + + Description + + 说明 + +
decoratorsLeave the decorators in place. This makes compilation faster. TypeScript will emit calls to the __decorate helper. Use --emitDecoratorMetadata for runtime reflection. However, the resulting code will not properly tree-shake. + + Leave the decorators in place. This makes compilation faster. TypeScript will emit calls to the __decorate helper. Use --emitDecoratorMetadata for runtime reflection. However, the resulting code will not properly tree-shake. + + 把装饰器留在原地。这会让编译更快。TypeScript 会调用 __decorate 助手。使用 --emitDecoratorMetadata 来支持运行时反射。但是,这会导致代码无法被正确的摇树优化。 + +
static fieldsReplace decorators with a static field in the class. Allows advanced tree-shakers like - Closure compiler to remove unused classes. + + Replace decorators with a static field in the class. Allows advanced tree-shakers like + Closure compiler to remove unused classes. + + 用类中的静态字段替换装饰器,允许使用 Closure compiler 等高级摇树优化器来删除未使用的类。 + +
@@ -1976,6 +2540,8 @@ annotations and decorators are unaffected. Default is `static fields`. This tells the compiler to print extra information while compiling templates. +这会告诉编译器在编译模板时打印出额外的信息。 + ### *enableLegacyTemplate* Use of the `