diff --git a/aio/content/guide/ajs-quick-reference.md b/aio/content/guide/ajs-quick-reference.md index 62b74d5755..1f6d221268 100644 --- a/aio/content/guide/ajs-quick-reference.md +++ b/aio/content/guide/ajs-quick-reference.md @@ -542,7 +542,7 @@ AngularJS 为模板提供了七十多个内置指令。 For more information on routing, see [Defining a basic route](guide/router#basic-route) in the [Routing & Navigation](guide/router) page. - 要了解关于路由的更多信息,请参见[路由与导航](guide/router)的[RouterLink 绑定](guide/router#router-link)部分。 + 要了解关于路由的更多信息,请参见[路由与导航](guide/router)的[定义基础路由](guide/router#basic-route)部分。 diff --git a/aio/content/guide/aot-compiler.md b/aio/content/guide/aot-compiler.md index 0c431a2c96..5ebb192fe4 100644 --- a/aio/content/guide/aot-compiler.md +++ b/aio/content/guide/aot-compiler.md @@ -19,7 +19,7 @@ This guide explains how to specify metadata and apply available compiler options Watch Alex Rickabaugh explain the Angular compiler at AngularConnect 2019. - 观看编译器作者 Tobias Bosch 在 AngularConnect 2016 大会里,对Angular 编译器的演讲。 + 观看 Alex Rickabaugh 在 AngularConnect 2019 解释 Angular 编译器的演讲 . diff --git a/aio/content/guide/architecture-components.md b/aio/content/guide/architecture-components.md index a04655b63d..bb49a27b0c 100644 --- a/aio/content/guide/architecture-components.md +++ b/aio/content/guide/architecture-components.md @@ -5,7 +5,7 @@ A *component* controls a patch of screen called a [*view*](guide/glossary#view "Definition of view"). For example, individual components define and control each of the following views from the [Tour of Heroes tutorial](tutorial): -*组件*控制屏幕上被称为*视图*的一小片区域。比如,[教程](tutorial/index)中的下列视图都是由一个个组件所定义和控制的: +*组件*控制屏幕上被称为[*视图*](guide/glossary#view "Definition of view")的一小片区域。比如,[教程](tutorial/index)中的下列视图都是由一个个组件所定义和控制的: * The app root with the navigation links. diff --git a/aio/content/guide/dependency-injection-in-action.md b/aio/content/guide/dependency-injection-in-action.md index 26311fb07d..9459d1b5cb 100644 --- a/aio/content/guide/dependency-injection-in-action.md +++ b/aio/content/guide/dependency-injection-in-action.md @@ -845,9 +845,12 @@ The `MinimalLogger` transpiles to this unoptimized, pre-minified JavaScript for Notice that it doesn't have any members. It never grows no matter how many members you add to the class, -as long as those members are typed but not implemented. Look again at the TypeScript `MinimalLogger` class to confirm that it has no implementation. +as long as those members are typed but not implemented. 注意,***只要不实现它***,不管添加多少成员,它都不会增长大小,因为这些成员虽然是有类型的,但却没有实现。 + +Look again at the TypeScript `MinimalLogger` class to confirm that it has no implementation. + 你可以再看看 TypeScript 的 `MinimalLogger` 类,确定一下它是没有实现的。 diff --git a/aio/content/guide/deprecations.md b/aio/content/guide/deprecations.md index 0bc90bfdbc..93f47d44c6 100644 --- a/aio/content/guide/deprecations.md +++ b/aio/content/guide/deprecations.md @@ -607,17 +607,17 @@ export class MyModule { {@a ie-9-10} ### IE 9 and 10 support -### IE 9 和 10 支持 IE 9 +### IE 9 和 10 支持 Support for IE 9 and 10 has been deprecated and will be removed in a future version. Supporting outdated browsers like these increases bundle size, code complexity, and test load, and also requires time and effort that could be spent on improvements to the framework. For example, fixing issues can be more difficult, as a straightforward fix for modern browsers could break old ones that have quirks due to not receiving updates from vendors. -对 IE 9 和 10 的支持已被弃用,并将在以后的版本中删除。支持像这样过时的浏览器会增加 bundle 的大小,增加代码的复杂性和测试的负载,还需要花费大量的时间和精力来改进框架。例如,修复问题可能会更加困难,因为对于现代浏览器来说,直接修复可能会因为没有收到供应商的更新而破坏那些有怪癖的旧版本。 +对 IE 9 和 10 的支持已被弃用,并将在以后的版本中删除。支持像这样过时的浏览器会增加打包尺寸,增加代码的复杂性和测试的负担,还需要花费大量的时间和精力来改进框架。例如,修复问题可能会更加困难,因为对于现代浏览器那些直接的修复方式可能会破坏那些没有收到更新的怪异旧版本。 The final decision was made on three key points: -最终决定于三个关键点: +它的最终决定取决于三点: - **Vendor support**: Microsoft dropped support of IE 9 and 10 on 1/12/16, meaning they no longer provide security updates or technical support. @@ -625,7 +625,7 @@ The final decision was made on three key points: - **Usage statistics**: We looked at usage trends for IE 9 and 10 from various sources and all indicated that usage percentages were extremely small (fractions of 1%). - **用法统计** :我们从不同来源查看了 IE 9 和 10 的使用趋势,并且都表明使用率非常小(1%的分数)。 + **用法统计** :我们从不同来源查看了 IE 9 和 10 的使用趋势,并且都表明其使用率非常小(不足 1%)。 - **Feedback from partners**: We also reached out to some of our Angular customers and none expressed concern about dropping IE 9 and 10 support. @@ -640,16 +640,16 @@ The final decision was made on three key points: The purpose of `WrappedValue` is to allow the same object instance to be treated as different for the purposes of change detection. It is commonly used with the `async` pipe in the case where the `Observable` produces the same instance of the value. -`WrappedValue` 的目的是让同一个对象实例被视为不同的对象,以便进行变更检测。在 `Observable` 生成相同值的实例的情况下,它常用于 `async` 管道。 +`WrappedValue` 的目的是让同一个对象实例被视为不同的对象,以便进行变更检测。比如当 `Observable` 生成相同实例的时候,它常用于 `async` 管道。 Given that this use case is relatively rare and special handling impacts application performance, we have deprecated it in v10. No replacement is planned for this deprecation. -鉴于此用例相对较少,并且特殊处理会影响应用性能,因此我们已在第 10 版中弃用它。这次弃用并未计划更换。 +鉴于此用例相对较少,并且特殊处理会影响应用性能,因此我们已在第 10 版中弃用它。这项弃用并没有提供替代方案。 If you rely on the behavior that the same object instance should cause change detection, you have two options: -如果依赖同一个对象实例引起变更检测的行为,你有两个选择: +如果你要依赖同一个对象实例引起变更检测的行为,那么有两个选择: - Clone the resulting value so that it has a new identity. @@ -657,46 +657,46 @@ If you rely on the behavior that the same object instance should cause change de - Explicitly call [`ChangeDetectorRef.detectChanges()`](api/core/ChangeDetectorRef#detectchanges) to force the update. - 显式调用[`ChangeDetectorRef.detectChanges()`](api/core/ChangeDetectorRef#detectchanges)来强制进行更新。 + 显式调用 [`ChangeDetectorRef.detectChanges()`](api/core/ChangeDetectorRef#detectchanges) 进行强制更新。 {@a removed} ## Removed APIs -## 删除了 API +## 删除的 API The following APIs have been removed starting with version 10.0.0\*: -从 Version 10.0.0 \*开始,已经删除了以下 API: +从 10.0.0 版开始,已经删除了以下 API: | Package | API | Replacement | Notes | | ------- | --- | ----------- | ----- | -| 包裹 | API | 更换 | 笔记 | +| 包 | API | 替代品 | 备注 | | `@angular/core` | Undecorated base classes that use Angular features | Add Angular decorator | See [migration guide](guide/migration-undecorated-classes) for more info | -| `@angular/core` | 使用 Angular 特性的未修改的基类 | 添加 Angular 装饰器 | 有关详情,请参阅[迁移指南](guide/migration-undecorated-classes) | +| `@angular/core` | 使用 Angular 特性的不带装饰器的基类 | 添加 Angular 装饰器 | 详情参阅[迁移指南](guide/migration-undecorated-classes) | | `@angular/core` | `ModuleWithProviders` without a generic | `ModuleWithProviders` with a generic | See [migration guide](guide/migration-module-with-providers) for more info | -| `@angular/core` | `ModuleWithProviders` 没有泛型 | `ModuleWithProviders` 用泛型的 | 有关详情,请参阅[迁移指南](guide/migration-module-with-providers) | +| `@angular/core` | 不带泛型的 `ModuleWithProviders` | 带泛型的 `ModuleWithProviders` | 详情参阅[迁移指南](guide/migration-module-with-providers) | | `@angular/core` | Style Sanitization | no action needed | See [style sanitization API removal](#style-sanitization) for more info | -| `@angular/core` | 风格消毒 | 不需要任何动作 | 有关更多信息,请参阅[样式清理 API 删除](#style-sanitization) | +| `@angular/core` | 样式的无害化处理 | 不需要任何动作 | 详情参阅[移除了 样式无害化 API](#style-sanitization) | \*To see APIs removed in version 9, check out this guide on the [version 9 docs site](https://v9.angular.io/guide/deprecations#removed). -\*要查看版本 9 中移除的 API,请查看[版本 9 docs 站点](https://v9.angular.io/guide/deprecations#removed)上的本指南。 +\*要查看版本 9 中移除的 API,请查看[版本 9 文档站](https://v9.angular.io/guide/deprecations#removed)上本指南。 {@a esm5-fesm5} ### `esm5` and `fesm5` code formats in @angular/* npm packages -### @angular/* npm 软件包中的 `esm5` 和 `fesm5` 代码格式 +### `@angular/*` npm 软件包中的 `esm5` 和 `fesm5` 代码格式 As of Angular v8, the CLI primarily consumes the `fesm2015` variant of the code distributed via `@angular/*` npm packages. This renders the `esm5` and `fesm5` distributions obsolete and unnecessary, adding bloat to the package size and slowing down npm installations. -从 Angular v8 开始,CLI 就主要使用 通过 `@angular/*` 系列 npm 包分发的 `fesm2015` 变体代码。这就让 `esm5` 和 `fesm5` 的发行版变得过时和不必要,只会增加软件包大小并拖累了 npm 的安装速度。 +从 Angular v8 开始,CLI 就主要使用通过 `@angular/*` 系列 npm 包分发的 `fesm2015` 变体代码。这就让 `esm5` 和 `fesm5` 的发行版变得过时和不必要,只会增加软件包大小并拖累 npm 的安装速度。 This removal has no impact on CLI users, unless they modified their build configuration to explicitly consume these code distributions. -移除它们不会对 CLI 用户产生任何影响,除非他们修改了自己的构建配置以显式使用这些代码发行版。 +移除它们不会对 CLI 用户产生任何影响,除非他们修改了自己的构建配置以显式使用代码的这些发行版。 Any application still relying on the `esm5` and `fesm5` as the input to its build system will need to ensure that the build pipeline is capable of accepting JavaScript code conforming to ECMAScript 2015 (ES2015) language specification. @@ -754,17 +754,17 @@ For more information about the npm package format, see the [Angular Package Form {@a ie-9-10} ### IE 9 and 10 support -### 对 IE 9 和 10 的支持 +### IE 9 和 10 支持 Support for IE 9 and 10 has been deprecated and will be removed in a future version. Supporting outdated browsers like these increases bundle size, code complexity, and test load, and also requires time and effort that could be spent on improvements to the framework. For example, fixing issues can be more difficult, as a straightforward fix for modern browsers could break old ones that have quirks due to not receiving updates from vendors. -对 IE 9 和 10 的支持已被弃用,并将在以后的版本中删除。支持像这样过时的浏览器会增加 bundle 的大小,增加代码的复杂性和测试的负载,还需要花费大量的时间和精力来改进框架。例如,修复问题可能会更加困难,因为对于现代浏览器来说,直接修复可能会因为没有收到供应商的更新而破坏那些有怪癖的旧版本。 +对 IE 9 和 10 的支持已被弃用,并将在以后的版本中删除。支持像这样过时的浏览器会增加打包尺寸,增加代码的复杂性和测试的负担,还需要花费大量的时间和精力来改进框架。例如,修复问题可能会更加困难,因为对于现代浏览器那些直接的修复方式可能会破坏那些没有收到更新的怪异旧版本。 The final decision was made on three key points: -最终决定于三个关键点: +它的最终决定取决于三点: - **Vendor support**: Microsoft dropped support of IE 9 and 10 on 1/12/16, meaning they no longer provide security updates or technical support. @@ -772,7 +772,7 @@ The final decision was made on three key points: - **Usage statistics**: We looked at usage trends for IE 9 and 10 from various sources and all indicated that usage percentages were extremely small (fractions of 1%). - **用法统计** :我们从不同来源查看了 IE 9 和 10 的使用趋势,并且都表明使用率非常小(1%的分数)。 + **用法统计** :我们从不同来源查看了 IE 9 和 10 的使用趋势,并且都表明其使用率非常小(不足 1%)。 - **Feedback from partners**: We also reached out to some of our Angular customers and none expressed concern about dropping IE 9 and 10 support. @@ -781,23 +781,25 @@ The final decision was made on three key points: {@a removed} ## Removed APIs -## 已删除的 API +## 删除的 API -The following APIs have been removed starting with version 10.0.0*: +The following APIs have been removed starting with version 10.0.0\*: -从 9.0.0\*版开始,以下 API 已被删除: +从 10.0.0 版开始,已经删除了以下 API: -| Package | API | Replacement | Notes | -| ---------------- | -------------- | ----------- | ----- | -| 包 | API | 替代品 | 备注 | | -| `@angular/core` | Undecorated base classes that use Angular features | Add Angular decorator | See [migration guide](guide/migration-undecorated-classes) for more info | -| `@angular/core` | 用到 Angular 特性的不带装饰器的基类 | 添加 Angular 装饰器 | 欲知详情,参见[迁移指南](guide/migration-undecorated-classes) | -| `@angular/core` | `ModuleWithProviders` without a generic | `ModuleWithProviders` with a generic | See [migration guide](guide/migration-module-with-providers) for more info | -| `@angular/core` | 不带泛型的 `ModuleWithProviders` | 带泛型的 `ModuleWithProviders` | 欲知详情,参见 [迁移指南](guide/migration-module-with-providers) | +| Package | API | Replacement | Notes | +| ------- | --- | ----------- | ----- | +| 包 | API | 替代品 | 备注 | +| `@angular/core` | Undecorated base classes that use Angular features | Add Angular decorator | See [migration guide](guide/migration-undecorated-classes) for more info | +| `@angular/core` | 使用 Angular 特性的不带装饰器的基类 | 添加 Angular 装饰器 | 详情参阅[迁移指南](guide/migration-undecorated-classes) | +| `@angular/core` | `ModuleWithProviders` without a generic | `ModuleWithProviders` with a generic | See [migration guide](guide/migration-module-with-providers) for more info | +| `@angular/core` | 不带泛型的 `ModuleWithProviders` | 带泛型的 `ModuleWithProviders` | 详情参阅[迁移指南](guide/migration-module-with-providers) | +| `@angular/core` | Style Sanitization | no action needed | See [style sanitization API removal](#style-sanitization) for more info | +| `@angular/core` | 样式的无害化处理 | 不需要任何动作 | 详情参阅[移除了 样式无害化 API](#style-sanitization) | -*To see APIs removed in version 9, check out this guide on the [version 9 docs site](https://v9.angular.io/guide/deprecations#removed). +\*To see APIs removed in version 9, check out this guide on the [version 9 docs site](https://v9.angular.io/guide/deprecations#removed). -要查看版本 8 中删除的 API,请查看[版本 8 文档站点](https://v8.angular.io/guide/deprecations#removed)上的本指南。 +\*要查看版本 9 中移除的 API,请查看[版本 9 文档站](https://v9.angular.io/guide/deprecations#removed)上本指南。 {@a http} @@ -880,9 +882,9 @@ For more information about using `@angular/common/http`, see the [HttpClient gui ### Style Sanitization for `[style]` and `[style.prop]` bindings -### `[style]` 和 `[style.prop]` 绑定的 Style `[style.prop]` +### `[style]` 和 `[style.prop]` 绑定的样式无害化 Angular used to sanitize `[style]` and `[style.prop]` bindings to prevent malicious code from being inserted through `javascript:` expressions in CSS `url()` entries. However, most modern browsers no longer support the usage of these expressions, so sanitization was only maintained for the sake of IE 6 and 7. Given that Angular does not support either IE 6 or 7 and sanitization has a performance cost, we will no longer sanitize style bindings as of version 10 of Angular. -Angular 用来清理 `[style]` 和 `[style.prop]` 绑定,以防止恶意代码通过 CSS `url()` 条目中的 `javascript:` expressions 进行插入。但是,大多数现代浏览器都不再支持这些表达式的使用,所以只有 IE 6 和 7 才能维护清理。鉴于 Angular 不支持 IE 6 或 7,并且清理有性能代价,我们将不再清理 Angular 版本 10 中的样式绑定。 +Angular 会清理 `[style]` 和 `[style.prop]` 绑定,以防止恶意代码通过 CSS `url()` 条目中的 `javascript:` 表达式进行插入。但是,大多数现代浏览器都已不再支持这些表达式的使用,所以这种清理只对 IE 6 和 7 才有意义。鉴于 Angular 不支持 IE 6 或 7,并且这种清理有性能代价,因此我们将不再清理 Angular 版本 10 中的样式绑定。 diff --git a/aio/content/guide/displaying-data.md b/aio/content/guide/displaying-data.md index a2d9cf5be5..5771d2194d 100644 --- a/aio/content/guide/displaying-data.md +++ b/aio/content/guide/displaying-data.md @@ -241,7 +241,7 @@ Don't forget the leading asterisk (\*) in `*ngFor`. It is an essential part of t Read more about `ngFor` and `*` in the [ngFor section](guide/template-syntax#ngfor) of the [Template Syntax](guide/template-syntax) page. 不要忘记 `*ngFor` 中的前导星号 (\*)。它是语法中不可或缺的一部分。 -更多信息,见[模板语法](guide/template-syntax#ngFor)。 +关于 `ngFor` 和 `*` 的更多信息,参见[模板语法](guide/template-syntax#ngFor)页的 [ngFor 部分](guide/template-syntax#ngfor)。 @@ -305,7 +305,7 @@ of hero names into an array of `Hero` objects. For that you'll need a `Hero` cla This command creates the following code. -代码如下: +此命令创建了如下代码: @@ -429,6 +429,7 @@ The browser should refresh automatically and the message should disappear. 试一下。因为这个数组中有四个条目,所以消息应该显示出来。 回到 `app.component.ts`,从英雄数组中删除或注释掉一个元素。 浏览器应该自动刷新,消息应该会消失。 + ## Summary ## 小结 diff --git a/aio/content/guide/glossary.md b/aio/content/guide/glossary.md index a8d3b79431..7d71099d65 100644 --- a/aio/content/guide/glossary.md +++ b/aio/content/guide/glossary.md @@ -345,7 +345,7 @@ See also [Schematics CLI](#schematics-cli). A class with the `@Component()` [decorator](#decorator) that associates it with a companion [template](#template). Together, the component class and template define a [view](#view). -一个带有 `@Component()` [装饰器](#decorator)的类,和它的伴生[模板](#template)关联在一起。组件及其模板共同定义了一个[视图](#view)。 +一个带有 `@Component()` [装饰器](#decorator)的类,和它的伴生[模板](#template)关联在一起。组件类及其模板共同定义了一个[视图](#view)。 A component is a special type of [directive](#directive). The `@Component()` decorator extends the `@Directive()` decorator with template-oriented features. @@ -358,7 +358,7 @@ Angular 的组件类负责暴露数据,并通过[数据绑定机制](#data-bin Read more about component classes, templates, and views in [Introduction to Angular concepts](guide/architecture). -要了解更多关于组件、模板和视图的知识,参见 [架构概览](guide/architecture) 一章。 +要了解更多关于组件类、模板和视图的知识,参见 [架构概览](guide/architecture) 一章。 ## configuration @@ -682,14 +682,14 @@ Compare to [custom element](#custom-element). ## 入口点(Entry Point) -A JavaScript module(#module) that is intended to be imported by a user of [an +A [JavaScript module](#module) that is intended to be imported by a user of [an npm package](guide/npm-packages). An entry-point module typically re-exports symbols from other internal modules. A package can contain multiple entry points. For example, the `@angular/core` package has two entry-point modules, which can be imported using the module names `@angular/core` and `@angular/core/testing`. -JavaScript 模块(#module)的目的是供 [npm 包](guide/npm-packages)的用户进行导入。入口点模块通常会重新导出来自其它内部模块的一些符号。每个包可以包含多个入口点。比如 `@angular/core` 就有两个入口点模块,它们可以使用名字 `@angular/core` 和 `@angular/core/testing` 进行导入。 +[JavaScript 模块](#module)的目的是供 [npm 包](guide/npm-packages)的用户进行导入。入口点模块通常会重新导出来自其它内部模块的一些符号。每个包可以包含多个入口点。比如 `@angular/core` 就有两个入口点模块,它们可以使用名字 `@angular/core` 和 `@angular/core/testing` 进行导入。 {@a F} @@ -826,10 +826,9 @@ or displayed between element tags, as in this example. [属性数据绑定 (property data binding)](#data-binding) 的一种形式,位于双大括号中的[模板表达式 (template expression)](#template-expression)会被渲染成文本。 在被赋值给元素属性或者显示在元素标签中之前,这些文本可能会先与周边的文本合并,参见下面的例子。 - - - - +```html + +``` Read more about [interpolation](guide/template-syntax#interpolation) in [Template Syntax](guide/template-syntax). @@ -1501,7 +1500,7 @@ You can also define a custom builder, and add a target to the project configurat Code that defines how to render a component's [view](#view). -模板是与组件相关的代码,用来定义如何在 HTML 中渲染组件的[视图](#view)。 +用来定义要如何在 HTML 中渲染组件[视图](#view)的代码。 A template combines straight HTML with Angular [data-binding](#data-binding) syntax, [directives](#directive), and [template expressions](#template-expression) (logical constructs). @@ -1511,7 +1510,7 @@ The Angular elements insert or calculate values that modify the HTML elements be A template is associated with a [component class](#component) through the `@Component()` [decorator](#decorator). The template code can be provided inline, as the value of the `template` property, or in a separate HTML file linked through the `templateUrl` property. -模板通过 `@Component()` [装饰器](#decorator)与[组件](#component)类关联起来。其 HTML 可以作为 `template` 属性的值用内联的方式提供,也可以通过 `templateUrl` 属性链接到一个独立的 HTML 文件。 +模板通过 `@Component()` [装饰器](#decorator)与[组件类](#component)类关联起来。模板代码可以作为 `template` 属性的值用内联的方式提供,也可以通过 `templateUrl` 属性链接到一个独立的 HTML 文件。 Additional templates, represented by `TemplateRef` objects, can define alternative or *embedded* views, which can be referenced from multiple components. @@ -1654,7 +1653,7 @@ Views are typically collected into [view hierarchies](#view-tree). [组件 (component)](#component) 类及其关联的[模板 (template)](#template)定义了一个视图。 具体实现上,视图由一个与该组件相关的 `ViewRef` 实例表示。 -属于某个组件的视图叫做*宿主视图*。 +直属于某个组件的视图叫做*宿主视图*。 通常会把视图组织成一些[视图树(view hierarchies)](#view-tree)。 Properties of elements in a view can change dynamically, in response to user actions; diff --git a/aio/content/guide/ivy-compatibility-examples.md b/aio/content/guide/ivy-compatibility-examples.md index 1ebf8d5712..adcc793a11 100644 --- a/aio/content/guide/ivy-compatibility-examples.md +++ b/aio/content/guide/ivy-compatibility-examples.md @@ -1,18 +1,29 @@ # Ivy compatibility examples +# Ivy 的兼容性例子 + This appendix is intended to provide more background on Ivy changes. Many of these examples list error messages you may see, so searching by error message might be a good idea if you are debugging. +本附录旨在为 Ivy 的变更提供更多背景信息。其中很多例子列出了你可能会看到的错误信息,所以如果你正在调试,按错误信息搜索可能是个好主意。 +
NOTE: Most of these issues affect a small percentage of applications encountering unusual or rare edge cases.
{@a content-children-descendants} + ## @ContentChildren queries only match direct children by default +## @ContentChildren 查询默认只匹配直接子组件 + ### Basic example of change +### 变更的基本例子 + Let's say a component (`Comp`) has a `@ContentChildren` query for `'foo'`: +假设某个组件( `Comp` )对 `'foo'` 有 `@ContentChildren` 查询: + ```html
@@ -24,17 +35,27 @@ Let's say a component (`Comp`) has a `@ContentChildren` query for `'foo'`: In the previous runtime, the `
` with `#foo` would match. With Ivy, that `
` does not match because it is not a direct child of ``. +在之前的运行时中,带 `#foo` 的 `
` 会匹配到。而在 Ivy 中, `
` 不能匹配,因为它不是 `` 的直接子节点。 + ### Background +### 背景 + By default, `@ContentChildren` queries have the `descendants` flag set to `false`. +默认情况下, `@ContentChildren` 查询的 `descendants` 标志设置为 `false` 。 + In the previous rendering engine, "descendants" referred to "descendant directives". An element could be a match as long as there were no other directives between the element and the requesting directive. This made sense for directives with nesting like tabs, where nested tab directives might not be desirable to match. However, this caused surprising behavior for users because adding an unrelated directive like `ngClass` to a wrapper element could invalidate query results. +在前面的渲染引擎中,“descendants” 指的是“后代指令”。只要元素和请求指令之间没有其它指令,元素就可以匹配。这对于类似于 tabs (页标签组)的嵌套的指令是有意义的,其中嵌套的 tab 指令可能不适合匹配。但是,这会给用户带来令人惊讶的行为,因为只要在包装器元素中添加一个不相关的指令(如 `ngClass`) 就可能会让查询结果无效。 + For example, with the content query and template below, the last two `Tab` directives would not be matches: +例如,如果使用下面的内容查询和模板,最后两个 `Tab` 指令不匹配: + ``` @ContentChildren(Tab, {descendants: false}) tabs: QueryList ``` @@ -56,6 +77,8 @@ For example, with the content query and template below, the last two `Tab` direc In addition, the differences between type and string predicates were subtle and sometimes unclear. For example, if you replace the type predicate above with a `'foo'` string predicate, the matches change: +另外,使用类型谓词和使用字符串谓词之间的差异很微妙,有时甚至都分不清。例如,如果用 `'foo'` 字符串谓词替换上面的类型谓词,匹配就会改变: + ``` @ContentChildren('foo', {descendants: false}) foos: QueryList ``` @@ -79,7 +102,12 @@ Instead, we simplified the mental model so that "descendants" refers to DOM nest Any DOM element between the requesting component and a potential match will invalidate that match. Type predicates and string predicates also have identical matching behavior. +由于之前的行为对用户来说是不一致和令人惊讶的,所以我们不打算在 Ivy 中重现它。相反,我们简化了其心智模型,以便 “descendants” 只标识 DOM 嵌套。位于发出请求的组件和潜在匹配项之间的任何 DOM 元素都会使该匹配失效。类型谓词和字符串谓词也有了相同的匹配行为。 + Ivy behavior for directive/string predicates: + +指令/字符串谓词的 Ivy 行为: + ```
@@ -96,27 +124,45 @@ Ivy behavior for directive/string predicates: ### Example of error +### 错误信息的例子 + The error message that you see will depend on how the particular content query is used in the application code. Frequently, an error is thrown when a property is referenced on the content query result (which is now `undefined`). +你看到的错误信息取决于应用代码中特定的内容查询的使用方式。当在内容查询结果中引用一个属性(这里是 `undefined`)时,就会抛出一个错误。 + For example, if the component sets the content query results to a property, `foos`, `foos.first.bar` would throw the error: +例如,如果组件把内容查询结果设置为属性,那么 `foos`、`foos.first.bar` 会抛出错误: + ``` Uncaught TypeError: Cannot read property 'bar' of undefined ``` If you see an error like this, and the `undefined` property refers to the result of a `@ContentChildren` query, it may well be caused by this change. +如果你看到这样的错误,并且 `undefined` 属性引用了 `@ContentChildren` 查询的结果,那么很可能就是由于这个变化造成的。 + ### Recommended fix +### 推荐的修复方式 + You can either add the `descendants: true` flag to ignore wrapper elements or remove the wrapper elements themselves. +你可以添加 `descendants: true` 标志来忽略包装元素,也可以自己删除包装元素。 + Option 1: + +方案 1: + ``` @ContentChildren('foo', {descendants: true}) foos: QueryList; ``` Option 2: + +方案 2: + ```
@@ -124,12 +170,19 @@ Option 2: ``` {@a undecorated-classes} + ## All classes that use Angular DI must have an Angular class-level decorator +## 所有使用 Angular DI 的类都必须有一个 Angular 类级装饰器 + ### Basic example of change: +### 变更的基本例子: + In the previous rendering engine, the following would work: +在以前的渲染引擎中,下列代码可以正常工作: + ``` export class DataService { constructor(@Inject('CONFIG') public config: DataConfig) {} @@ -141,8 +194,12 @@ export class AppService extends DataService {...} In Ivy, it will throw an error because `DataService` is using Angular dependency injection, but is missing an `@Injectable` decorator. +在 Ivy 中,它会抛出一个错误,因为 `DataService` 正在使用 Angular 依赖注入,但它却缺少一个 `@Injectable` 装饰器。 + The following would also work in the previous rendering engine, but in Ivy would require a `@Directive` decorator because it uses DI: +下列渲染引擎也能正常工作,但是 Ivy 需要一个 `@Directive` 装饰器,因为它使用了 DI: + ``` export class BaseMenu { constructor(private vcr: ViewContainerRef) {} @@ -154,25 +211,41 @@ export class SettingsMenu extends BaseMenu {} The same is true if your directive class extends a decorated directive, but does not have a decorator of its own. +如果指令类扩展了装饰指令,但却没有自己的装饰器,那也是如此。 + If you're using the CLI, there are two automated migrations that should transition your code for you ([this one](guide/migration-injectable) and [this one](guide/migration-undecorated-classes)). However, as you're adding new code in version 9, you may run into this difference. +如果你正在使用 CLI,那么有两个自动迁移应该为你转移你的代码( [本章](guide/migration-injectable)和[本章](guide/migration-undecorated-classes) )。但是,当你在版本 9 中添加新代码时,可能会遇到这种不同。 + ### Background +### 背景 + When a class has an Angular decorator like `@Injectable` or `@Directive`, the Angular compiler generates extra code to support injecting dependencies into the constructor of your class. When using inheritance, Ivy needs both the parent class and the child class to apply a decorator to generate the correct code. Otherwise, when the decorator is missing from the parent class, the subclass will inherit a constructor from a class for which the compiler did not generate special constructor info, and Angular won't have the dependency info it needs to create it properly. +当一个类有一个像 `@Injectable` 或 `@Directive` 这样的 Angular 装饰器时,Angular 编译器会生成额外的代码,以支持把依赖注入到类的构造函数中。当使用继承时,Ivy 既需要父类,也要让子类应用装饰器来生成正确的代码。否则,当父类中缺少装饰器时,该子类将继承一个构造函数,而这个构造函数并没有为编译器生成特殊的构造函数信息,而 Angular 也没有正确创建它所需的依赖信息。 + In the previous rendering engine, the compiler had global knowledge, so in some cases (such as AOT mode or the presence of certain injection flags), it could look up the missing data. However, the Ivy compiler only processes each class in isolation. This means that compilation has the potential to be faster (and opens the framework up for optimizations and features going forward), but the compiler can't automatically infer the same information as before. +在之前的渲染引擎中,编译器具有全局知识,所以在某些情况下(比如 AOT 模式或某些注入标志的存在),它可以查找丢失的数据。然而,Ivy 编译器只是孤立地处理每个类。这意味着编译有可能更快(并为今后的优化和特性打开框架),但编译器不能自动推断出和以前一样的信息。 + Adding the proper decorator explicitly provides this information. +添加合适的装饰器会明确提供这些信息。 + ### Example of error +### 错误信息的例子 + In JIT mode, the framework will throw the following error: +在 JIT 模式下,该框架会抛出以下错误: + ``` ERROR: This constructor is not compatible with Angular Dependency Injection because its dependency at index X of the parameter list is invalid. This can happen if the dependency type is a primitive like a string or if an ancestor of this class is missing an Angular decorator. @@ -182,6 +255,8 @@ Please check that 1) the type for the parameter at index X is correct and 2) the In AOT mode, you'll see something like: +在 AOT 模式下,你会看到如下内容: + ``` X inherits its constructor from Y, but the latter does not have an Angular decorator of its own. Dependency injection will not be able to resolve the parameters of Y's constructor. Either add a @@ -192,16 +267,24 @@ In some cases, the framework may not be able to detect the missing decorator. In these cases, you'll generally see a runtime error thrown when there is a property access attempted on the missing dependency. If dependency was `foo`, you'd see an error when accessing something like `foo.bar`: +在某些情况下,框架可能无法检测到丢失的装饰器。在这种情况下,你会发现试图对所缺的依赖项进行属性访问时,就会抛出一个运行时错误。如果依赖是 `foo` ,你在访问 `foo.bar` 这样的东西时会看到一个错误: + ``` Uncaught TypeError: Cannot read property 'bar' of undefined ``` If you see an error like this, and the `undefined` value refers to something that should have been injected, it may be this change. +如果你看到这样的错误,并且 `undefined` 值引用了应该注入的内容,那么可能就是这种变化。 + ### Recommended fix +### 推荐的修复方式 + - Add an `@Injectable` decorator to anything you plan to provide or inject. + 把 `@Injectable` 装饰器添加到你打算提供或注入的东西中。 + ``` @Injectable() export class DataService { @@ -214,6 +297,8 @@ export class AppService extends DataService {...} - Add a [selectorless `@Directive` decorator](guide/migration-undecorated-classes#what-does-it-mean-to-have-a-directive-decorator-with-no-metadata-inside-of-it) to any class that extends a directive or any class from which a directive inherits. + 把 [无选择器的 `@Directive` 装饰器](guide/migration-undecorated-classes#what-does-it-mean-to-have-a-directive-decorator-with-no-metadata-inside-of-it)添加到扩展指令的类或被指令继承的任何类中。 + ``` @Directive() // selectorless, so it's not usable directly export class BaseMenu { @@ -225,10 +310,15 @@ export class SettingsMenu extends BaseMenu {} ``` {@a select-value-binding} + ## Cannot Bind to `value` property of `` 的 `value` 属性 + ### Basic example of change +### 变更的基本例子 + ```html ` as expected. In Ivy, the initial value would not be set at all in this case. +在 View Engine 的运行时,上面的代码会按照预期的那样设置 `