# Deprecated APIs and features # 弃用的 API 和特性 Angular strives to balance innovation and stability. Sometimes, APIs and features become obsolete and need to be removed or replaced so that Angular can stay current with new best practices, changing dependencies, or changes in the (web) platform itself. Angular 力图兼顾创新与稳定。但有时,API 和特性已经过时,需要进行删除或替换,以便 Angular 可以及时跟上新的最佳实践、依赖项变更或者 Web 平台自身的变化。 To make these transitions as easy as possible, we deprecate APIs and features for a period of time before removing them. This gives you time to update your apps to the latest APIs and best practices. 为了让这些转换变得尽可能简单,我们会在删除 API 和特性之前先弃用它们一段时间。让你有时间把应用更新到最新的 API 和最佳实践。 This guide contains a summary of all Angular APIs and features that are currently deprecated. 本指南包含了当前不推荐使用的所有 Angular API 和特性的汇总表。
Features and APIs that were deprecated in v6 or earlier are candidates for removal in version 9 or any later major version. For information about Angular's deprecation and removal practices, see [Angular Release Practices](guide/releases#deprecation-practices "Angular Release Practices: Deprecation practices"). v6 或更早版本中已弃用的特性和 API 将会在版本 9 或更高级版本中删除。要了解 Angular 中关于弃用和删除的实践,参见[Angular 发布实践](guide/releases#deprecation-practices "Angular 发布实践:弃用实践") 。 For step-by-step instructions on how to update to the latest Angular release, use the interactive update guide at [update.angular.io](https://update.angular.io). 有关如何更新到最新 Angular 版本的分步说明,参见 [update.angular.io](https://update.angular.io) 上的交互式更新指南。
## Index ## 索引 To help you future-proof your apps, the following table lists all deprecated APIs and features, organized by the release in which they are candidates for removal. Each item is linked to the section later in this guide that describes the deprecation reason and replacement options. 为了帮助您确保应用程序的前瞻性,下表列出了所有已弃用的 API 和功能,这些 API 和功能按发行版进行组织,它们将被删除。每个条目都链接到本指南后面的部分,该部分描述了弃用原因和替换选项。 | Area | API or Feature | May be removed in | | ---- | -------------- | ----------------- | | 区域 | API 或特性 | 可能会在什么时候移除 | | `@angular/common` | [`ReflectiveInjector`](#reflectiveinjector) | v10 | | `@angular/common` | [`CurrencyPipe` - `DEFAULT_CURRENCY_CODE`](api/common/CurrencyPipe#currency-code-deprecation) | v11 | | `@angular/core` | [`CollectionChangeRecord`](#core) | v10 | | `@angular/core` | [`DefaultIterableDiffer`](#core) | v10 | | `@angular/core` | [`ReflectiveKey`](#core) | v10 | | `@angular/core` | [`RenderComponentType`](#core) | v10 | | `@angular/core` | [`ViewEncapsulation.Native`](#core) | v10 | | `@angular/core` | [`ModuleWithProviders` without a generic](#moduleWithProviders) | v10 | | `@angular/core` | [不带泛型的 `ModuleWithProviders`](#moduleWithProviders) | v10 | | `@angular/core` | [Undecorated base classes that use Angular features](#undecorated-base-classes) | v10 | | `@angular/core` | [使用 Angular 特性的不带装饰器的基类](#undecorated-base-classes) | v10 | | `@angular/forms` | [`ngModel` with reactive forms](#ngmodel-reactive) | v10 | | `@angular/forms` | [响应式表单中的 `ngModel`](#ngmodel-reactive) | v10 | | `@angular/router` | [`preserveQueryParams`](#router) | v10 | | `@angular/upgrade` | [`@angular/upgrade`](#upgrade) | v10 | | `@angular/upgrade` | [`getAngularLib`](#upgrade-static) | v10 | | `@angular/upgrade` | [`setAngularLib`](#upgrade-static) | v10 | | `@angular/platform-webworker` | [All entry points](api/platform-webworker) | v10  | | `@angular/platform-webworker` | [所有入口点](api/platform-webworker) | v10 | | template syntax | [`](#template-tag) | v10 | | 模板语法 | [`](#template-tag) | v10 | | polyfills | [reflect-metadata](#reflect-metadata) | v10 | | 腻子脚本 | [reflect-metadata](#reflect-metadata) | v10 | | npm package format | [`esm5` and `fesm5` entry-points in @angular/\* npm packages](guide/deprecations#esm5-fesm5) | v10 | | npm 软件包格式 | [@angular/\* npm 软件包中的 `esm5` 和 `fesm5` 入口点](guide/deprecations#esm5-fesm5) | v10 | | `@angular/core` | [`defineInjectable`](#core) | v11 | | `@angular/core` | [`entryComponents`](api/core/NgModule#entryComponents) | v11 | | `@angular/core` | [`ANALYZE_FOR_ENTRY_COMPONENTS`](api/core/ANALYZE_FOR_ENTRY_COMPONENTS) | v11 | | `@angular/router` | [`loadChildren` string syntax](#loadChildren) | v11 | | `@angular/router` | [`loadChildren` 字符串语法](#loadChildren) | v11 | | `@angular/core/testing` | [`TestBed.get`](#testing) | v12 | | `@angular/router` | [`ActivatedRoute` params and `queryParams` properties](#activatedroute-props) | unspecified | | `@angular/router` | [`ActivatedRoute` 参数和 `queryParams` 属性](#activatedroute-props) | 未定 | | template syntax | [`/deep/`, `>>>`, and `::ng-deep`](#deep-component-style-selector) | unspecified | | 模板语法 | [`/deep/`,`>>>` 和 `::ng-deep`](#deep-component-style-selector) | 未定 | ## Deprecated APIs ## 已弃用的 API This section contains a complete list all of the currently-deprecated APIs, with details to help you plan your migration to a replacement. 本节包含所有当前已弃用的 API 的完整列表,其中包含一些可帮助你规划如何迁移到其替代品的详细信息。
Tip: In the [API reference section](api) of this doc site, deprecated APIs are indicated by ~~strikethrough.~~ You can filter the API list by [**Status: deprecated**](api?status=deprecated). 提示:在本文档站的 [API参考手册部分](api),不推荐使用的 API 会用~~删除线~~标记出来。你可以按[**状态**: 已弃用](api?status=deprecated)来过滤 API 列表。
{@a common} ### @angular/common | API | Replacement | Deprecation announced | Notes | | --------------------------------------------------------------------------------------------- | --------------------------------------------------- | --------------------- | ----- | | [`CurrencyPipe` - `DEFAULT_CURRENCY_CODE`](api/common/CurrencyPipe#currency-code-deprecation) | `{provide: DEFAULT_CURRENCY_CODE, useValue: 'USD'}` | v9 | From v11 the default code will be extracted from the locale data given by `LOCAL_ID`, rather than `USD`. | | [`CurrencyPipe` - `DEFAULT_CURRENCY_CODE`](api/common/CurrencyPipe#currency-code-deprecation) | `{provide: DEFAULT_CURRENCY_CODE, useValue: 'USD'}` | v9 | 从 v11 开始,默认代码将从由 `LOCAL_ID` 提供的语言环境数据中提取,而不再是固定值 `USD`。 | {@a core} ### @angular/core | API | Replacement | Deprecation announced | Notes | | --- | ----------- | --------------------- | ----- | | API | 替代品 | 宣布弃用 | 备注 | | [`CollectionChangeRecord`](api/core/CollectionChangeRecord) | [`IterableChangeRecord`](api/core/IterableChangeRecord) | v4 | none | | [`CollectionChangeRecord`](api/core/CollectionChangeRecord) | [`IterableChangeRecord`](api/core/IterableChangeRecord) | v4 | 无 | | [`DefaultIterableDiffer`](api/core/DefaultIterableDiffer) | n/a | v4 | Not part of public API. | | [`DefaultIterableDiffer`](api/core/DefaultIterableDiffer) | 不适用 | v4 | 不属于公共API。 | | [`ReflectiveInjector`](api/core/ReflectiveInjector) | [`Injector.create`](api/core/Injector#create) | v5 | See [`ReflectiveInjector`](#reflectiveinjector) | | [`ReflectiveInjector`](api/core/ReflectiveInjector) | [`Injector.create`](api/core/Injector#create) | v5 | 参见 [`ReflectiveInjector`](#reflectiveinjector) | | [`ReflectiveKey`](api/core/ReflectiveKey) | none | v5 | none | | [`ReflectiveKey`](api/core/ReflectiveKey) | 无 | v5 | 无 | | [`ViewEncapsulation.Native`](api/core/ViewEncapsulation#Native) | [`ViewEncapsulation.ShadowDom`](api/core/ViewEncapsulation#ShadowDom) | v6 | Use the native encapsulation mechanism of the renderer. See [view.ts](https://github.com/angular/angular/blob/3e992e18ebf51d6036818f26c3d77b52d3ec48eb/packages/core/src/metadata/view.ts#L32). | | [`ViewEncapsulation.Native`](api/core/ViewEncapsulation#Native) | [`ViewEncapsulation.ShadowDom`](api/core/ViewEncapsulation#ShadowDom) | v6 | 使用渲染器的原生封装机制。参见 [view.ts。](https://github.com/angular/angular/blob/3e992e18ebf51d6036818f26c3d77b52d3ec48eb/packages/core/src/metadata/view.ts#L32) | | [`defineInjectable`](api/core/defineInjectable) | `ɵɵdefineInjectable` | v8 | Used only in generated code. No source code should depend on this API. | | [`defineInjectable`](api/core/defineInjectable) | `ɵɵdefineInjectable` | v8 | 仅在生成的代码中使用。任何源代码都不应依赖此API。 | | [`entryComponents`](api/core/NgModule#entryComponents) | none | v9 | See [`entryComponents`](#entryComponents) | | [`entryComponents`](api/core/NgModule#entryComponents) | 无 | v9 | 参见 [`entryComponents`](#entryComponents) | | [`ANALYZE_FOR_ENTRY_COMPONENTS`](api/core/ANALYZE_FOR_ENTRY_COMPONENTS) | none | v9 | See [`ANALYZE_FOR_ENTRY_COMPONENTS`](#entryComponents) | | [`ANALYZE_FOR_ENTRY_COMPONENTS`](api/core/ANALYZE_FOR_ENTRY_COMPONENTS) | 无 | v9 | 参见 [`ANALYZE_FOR_ENTRY_COMPONENTS`](#entryComponents) | | `ModuleWithProviders` without a generic | `ModuleWithProviders` with a generic | v9 | See [`ModuleWithProviders` section](#moduleWithProviders) | | 不带泛型的`ModuleWithProviders` | 带泛型的 `ModuleWithProviders` | v9 | 参见 [`ModuleWithProviders`部分](#moduleWithProviders) | | Undecorated base classes that use Angular features | Base classes with `@Directive()` decorator that use Angular features | v9 | See [undecorated base classes section](#undecorated-base-classes) | | 使用 Angular 功能的不带装饰器的基类 | 具有 Angular 功能的带 `@Directive()` 装饰器的基类 | v9 | 请参见[不带装饰器的基类部分](#undecorated-base-classes) | {@a testing} ### @angular/core/testing | API | Replacement | Deprecation announced | Notes | | --- | ----------- | --------------------- | ----- | | API | 替代品 | 宣布弃用 | 备注 | | [`TestBed.get`](api/core/testing/TestBed#get) | [`TestBed.inject`](api/core/testing/TestBed#inject) | v9 | Same behavior, but type safe. | | [`TestBed.get`](api/core/testing/TestBed#get) | [`TestBed.inject`](api/core/testing/TestBed#inject) | v9 | 行为相同,但类型安全。 | {@a forms} ### @angular/forms | API | Replacement | Deprecation announced | Notes | | --- | ----------- | --------------------- | ----- | | API | 替代品 | 宣布弃用 | 备注 | | [`ngModel` with reactive forms](#ngmodel-reactive) | See [FormControlDirective usage notes](api/forms/FormControlDirective#use-with-ngmodel) | v6 | none | | [响应式表单中的 `ngModel`](#ngmodel-reactive) | 参见 [FormControlDirective 使用说明](api/forms/FormControlDirective#use-with-ngmodel) | v6 | 无 | {@a router} ### @angular/router | API | Replacement | Deprecation announced | Notes | | --- | ----------- | --------------------- | ----- | | API | 替代品 | 宣布弃用 | 备注 | | [`preserveQueryParams`](api/router/NavigationExtras#preserveQueryParams) | [`queryParamsHandling`](api/router/NavigationExtras#queryParamsHandling) | v4 | none | | [`preserveQueryParams`](api/router/NavigationExtras#preserveQueryParams) | [`queryParamsHandling`](api/router/NavigationExtras#queryParamsHandling) | v4 | 无 | {@a platform-webworker} ### @angular/platform-webworker | API | Replacement | Deprecation announced | Notes | | --- | ----------- | --------------------- | ----- | | API | 替代品 | 宣布弃用 | 备注 | | [All entry points](api/upgrade) | [`@angular/upgrade/static`](api/upgrade/static) | v5 | See [Upgrading from AngularJS](guide/upgrade). | | [所有入口点](api/upgrade) | [`@angular/upgrade/static`](api/upgrade/static) | v5 | 参见[从 AngularJS 升级](guide/upgrade) 。 | {@a upgrade} ### @angular/upgrade | API | Replacement | Deprecation announced | Notes | | --- | ----------- | --------------------- | ----- | | API | 替代品 | 宣布弃用 | 备注 | | [All entry points](api/upgrade) | [`@angular/upgrade/static`](api/upgrade/static) | v5 | See [Upgrading from AngularJS](guide/upgrade). | | [所有入口点](api/upgrade) | [`@angular/upgrade/static`](api/upgrade/static) | v5 | 参见 [从 AngularJS 升级](guide/upgrade) 。 | {@a upgrade-static} ### @angular/upgrade/static | API | Replacement | Deprecation announced | Notes | | --- | ----------- | --------------------- | ----- | | API | 替代品 | 宣布弃用 | 备注 | | [`getAngularLib`](api/upgrade/static/getAngularLib) | [`getAngularJSGlobal`](api/upgrade/static/getAngularJSGlobal) | v5 | See [Upgrading from AngularJS](guide/upgrade). | | [`getAngularLib`](api/upgrade/static/getAngularLib) | [`getAngularJSGlobal`](api/upgrade/static/getAngularJSGlobal) | v5 | 参见[从 AngularJS 升级](guide/upgrade) 。 | | [`setAngularLib`](api/upgrade/static/setAngularLib) | [`setAngularJSGlobal`](api/upgrade/static/setAngularJSGlobal) | v5 | See [Upgrading from AngularJS](guide/upgrade). | | [`setAngularLib`](api/upgrade/static/setAngularLib) | [`setAngularJSGlobal`](api/upgrade/static/setAngularJSGlobal) | v5 | 参见[从 AngularJS 升级](guide/upgrade) 。 | {@a deprecated-features} ## Deprecated features ## 已弃用的特性 This section lists all of the currently-deprecated features, which includes template syntax, configuration options, and any other deprecations not listed in the [Deprecated APIs](#deprecated-apis) section above. It also includes deprecated API usage scenarios or API combinations, to augment the information above. 本节列出了所有当前已弃用的特性,包括模板语法、配置选项,以及前面[已弃用的 API ](#deprecated-apis)部分未列出的其它弃用。它还包括已弃用的 API 用例或 API 组合,以增强上述信息。 {@a wtf} ### Web Tracing Framework integration ### Web 跟踪框架集成 Angular previously has supported an integration with the [Web Tracing Framework (WTF)](https://google.github.io/tracing-framework/) for performance testing of Angular applications. This integration has not been maintained and defunct. As a result, the integration was deprecated in Angular version 8 and due to no evidence of any existing usage removed in version 9. Angular 以前支持与 [Web 跟踪框架(WTF)](https://google.github.io/tracing-framework/)集成,用于 Angular 应用程序的性能测试。此集成已经停止维护并失效。因此,该集成在 Angular 版本 8 中被弃用,并且由于没有证据表明在版本 9 中删除了任何现有用法。 {@a deep-component-style-selector} ### `/deep/`, `>>>` and `:ng-deep` component style selectors ### `/deep/` , `>>>` 和 `:ng-deep` 组件样式选择器 The shadow-dom-piercing descendant combinator is deprecated and support is being [removed from major browsers and tools](https://developers.google.com/web/updates/2017/10/remove-shadow-piercing). As such, in v4 we deprecated support in Angular for all 3 of `/deep/`, `>>>` and `::ng-deep`. Until removal, `::ng-deep` is preferred for broader compatibility with the tools. 刺穿 Shadow DOM 的 CSS 组合符已经弃用,并且[主要的浏览器和工具都已删除它](https://developers.google.com/web/updates/2017/10/remove-shadow-piercing)。因此,在 v4 中,Angular 也弃用了对 `/deep/`,`>>>` 和 `::ng-deep` 的支持。在彻底删除它之前,我们首选`::ng-deep` ,以便和各种工具实现更广泛的兼容。 For more information, see [/deep/, >>>, and ::ng-deep](guide/component-styles#deprecated-deep--and-ng-deep "Component Styles guide, Deprecated deep and ngdeep") in the Component Styles guide. 欲知详情,参阅“组件样式”一章中的 [/deep/,>>> 和 :: ng-deep](guide/component-styles#deprecated-deep--and-ng-deep "“组件样式”指南,代号为deep和ngdeep")。 {@a template-tag} ### <template> tag The `