angular-docs-cn/aio/content/guide/updating-to-version-9.md

6.5 KiB

Updating to Angular version 9

This guide contains information related to updating to version 9 of Angular.

Updating CLI Apps

For step-by-step instructions on how to update to the latest Angular release (and leverage our automated migration tools to do so), use the interactive update guide at update.angular.io.

If you're curious about the specific migrations being run by the CLI, see the automated migrations section for details on what code is changing and why.

Changes and Deprecations in Version 9

For information about Angular's deprecation and removal practices, see Angular Release Practices.

{@a breaking-changes}

New Breaking Changes

  • Angular now compiles with Ivy by default. See the Ivy compatibility section.

  • CLI apps compile in AOT mode by default (which includes template type-checking). Users who only built with JIT before may see new type errors. See our template type-checking guide for more information and debugging tips.

  • Typescript 3.4 and 3.5 are no longer supported. Please update to Typescript 3.7.

  • tslib is now listed as a peer dependency rather than a direct dependency. If you are not using the CLI, you must manually install tslib, using yarn add tslib or npm install tslib --save.

{@a deprecations}

New Deprecations

API Replacement Notes
entryComponents none See entryComponents
CurrencyPipe - DEFAULT_CURRENCY_CODE {provide: DEFAULT_CURRENCY_CODE, useValue: 'USD'} From v11 the default code will be extracted from the locale data given by LOCAL_ID, rather than USD.
ANALYZE_FOR_ENTRY_COMPONENTS none See ANALYZE_FOR_ENTRY_COMPONENTS
ModuleWithProviders without a generic ModuleWithProviders with a generic See ModuleWithProviders section
Undecorated base classes that use Angular features Base classes with @Directive() decorator that use Angular features See undecorated base classes section
esm5 and fesm5 distribution in @angular/* npm packages esm2015 and fesm2015 entrypoints See esm5 and fesm5
TestBed.get TestBed.inject Same behavior, but type safe.

{@a removals}

New Removals of Deprecated APIs

Package API Replacement Notes
@angular/core Renderer Renderer2 Migration guide.
@angular/core RootRenderer RendererFactory2 none
@angular/core RenderComponentType RendererType2 none
@angular/core WtfScopeFn none v8
@angular/core wtfCreateScope none v8
@angular/core wtfStartTimeRange none v8
@angular/core wtfEndTimeRange none v8
@angular/core wtfLeave none v8
@angular/common DeprecatedI18NPipesModule CommonModule none
@angular/common DeprecatedCurrencyPipe CurrencyPipe none
@angular/common DeprecatedDatePipe DatePipe none
@angular/common DeprecatedDecimalPipe DecimalPipe none
@angular/common DeprecatedPercentPipe PercentPipe none
@angular/forms NgFormSelectorWarning none
@angular/forms ngForm element selector ng-form element selector none
@angular/service-worker versionedFiles files In the service worker configuration file ngsw-config.json, replace versionedFiles with files. See Service Worker Configuration.

{@a ivy}

Ivy features and compatibility

In Version 9, Angular Ivy is the default rendering engine. If you haven't heard of Ivy, you can read more about it in the Angular Ivy guide.

  • Among other features, Ivy introduces more comprehensive type-checking within templates. For details, see Template Type-checking.

  • For general guidance on debugging and a list of minor changes associated with Ivy, see the Ivy compatibility guide.

  • For help with opting out of Ivy, see the instructions here.

{@a migrations}

Automated Migrations for Version 9

Read about the migrations the CLI handles for you automatically: