填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

更新 Angular

Updating Angular

本指南包含了關於更新到 Angular 最新版本的相關資訊。

This guide contains information related to updating to the latest version of Angular.

更新 CLI 應用

Updating CLI Apps

關於如何更新到最新版本 Angular(並利用我們的自動遷移工具)的分步說明,請參閱 update.angular.io 上的互動式更新指南。

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.

第 11 版的更改與棄用

Changes and Deprecations in Version 11

關於 Angular 的棄用和移除實踐的更多資訊,參閱 Angular 發佈實踐

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

新的重大變更

New Breaking Changes

  • 移除對 IE 9,10 和 IE mobile 的已棄用的支援。參閱 PR 38931

    Remove deprecated support for IE 9, 10, and IE mobile. See PR 38931.

  • 不再支援 TypeScript 3.9。請更新到 TypeScript 4.0。參閱 PR 39313

    TypeScript 3.9 is no longer supported. Please update to TypeScript 4.0. See PR 39313.

  • NavigationExtras#preserveQueryParams 已從 @angular/router 移除。參閱 PR 38762

    NavigationExtras#preserveQueryParams has been removed from @angular/router. See PR 38762

  • CollectionChangeRecord 已從 @angular/core 移除。參閱 PR 38668

    CollectionChangeRecord has been removed from @angular/core. See PR 38668.

  • relativeLinkResolution 的預設值從 'legacy' 更改為 'corrected' 以便新應用能自動從 PR 22394 中選擇糾正後的行為。使用當前預設值的應用可以透過一項針對 'legacy' 的遷移進行更新,以確保在預設值更新時保持當前的行為不變。參閱 PR 25609

    We changed the default value for relativeLinkResolution from 'legacy' to 'corrected' so that new applications are automatically opted-in to the corrected behavior from PR 22394. Applications which use the current default are updated by a migration to specify 'legacy' to ensure the current behavior is maintained when the default is updated. See PR 25609.

  • 修復了路由器中的一個 bug, shouldReuseRoute 在處理子路由時,在呼叫 futurecurr 快照的順序反了。這種順序上的錯誤通常無關緊要,因為大多數的 shouldReuseRoute實現只會在 futurecurr 之間做一個相等的比較。但是,有些實現確實依賴於兩者中的某一個值,並且要對其進行修改。參閱 PR 26949

    Fixed a bug in the router where the arguments for future and curr snapshots were reversed in the call to shouldReuseRoute when processing child routes. Usually this ordering mistake doesn't matter because most implementations of shouldReuseRoutejust do an equality comparison between future and curr. However, some implementations actually do rely on values specifically on one of the two and will need to be updated. See PR 26949.

  • ViewEncapsulation.Native 已被移除。 Angular 以前支援基於 v0 Shadow DOM Draft API 的檢視封裝模式 ViewEncapsulaion.Native。這些 API 已被最終版的 Shadow DOM API 所取代,後者透過 ViewEncapsulation.ShadowDom 啟用。關於此更改的背景資訊,請參閱 Web 元件更新:有更多時間升級到 v1 API 了

    ViewEncapsulation.Native has been removed. Angular previously supported a view encapsulation mode ViewEncapsulaion.Native that was based on the v0 Shadow DOM Draft APIs. These APIs have been superceded by the final Shadow DOM APIs, which are enabled via ViewEncapsulation.ShadowDom. For background information about this change, see Web Components update: more time to upgrade to v1 APIs.

  • @angular/platform-webworker 已被移除,並且不再受支援。參閱 PR 38846

    @angular/platform-webworker has been removed and will no longer be supported. See PR 38846.

  • 不再支援 @angular/platform-webworker。也不會發布更多版本。參閱 PR 38846

    @angular/platform-webworker is no longer supported. No further versions will be published. See PR 38846.

  • 更新了 initialNavigation 的選項。欲知詳情,請參閱 API 文件中的 initialNavigation。參閱 PR 33128

    Updated the options for initialNavigation. For more information, see initialNavigation in the API documentation. See PR 33128.

  • DatePipe 不再對毫秒的小數部分進行四捨五入。參閱 PR 38009

    DatePipe no longer rounds up fractional milliseconds. See PR 38009.

  • 現在,Locale 資料陣列是隻讀的。參閱 PR 30397

    Locale data arrays are now read-only. See PR 30397.

  • 現在為 NG_VALUE_ACCESSOR 注入的 ControlValueAccessor 是隻讀的。參閱 PR 29273

    The injected ControlValueAccessor for NG_VALUE_ACCESSOR is now readonly. See PR 29273.

  • AbstractControl#parent 的型別現在可以正確的表示出它可能為空。參閱 PR 32671

    The type of AbstractControl#parent now indicates that it may be null. See PR 32671.

  • 現在,在初始化 TestBed 之前呼叫 overrideProvider 會丟擲一個錯誤。參閱 PR 38717

    Calling overrideProvider before initializing the TestBed will now throw an error. See PR 38717.

  • 許多 Angular 內建管道的型別定義要麼縮小,要麼擴充套件得更準確。欲知詳情,請參閱相應的管道 API 文件。參閱 PR 37447

    Types for many Angular built-in pipes have been either narrowed or expanded to be more accurate. For more information, see the corresponding Pipes API documentation. See PR 37447.

  • @angular/forms 套件中的指令曾經把 any[] 作為建構函式中驗證器和非同步驗證器引數的型別。這些引數現在都具有正確型別了,所以如果你的程式碼依賴於指令的建構函式型別,它可能會需要一些更新才能提高其型別安全性。參閱 PR 38994

    Directives in the @angular/forms package used to have any[] as a type of validators and asyncValidators arguments in constructors. Now these arguments are properly typed, so if your code relies on directive constructor types it may require some updates to improve type safety. See PR 38994.

  • routerLink 現在接受 undefined 作為輸入。參閱 PR 39151

    routerLink now accepts undefined inputs. See PR 39151.

  • @angular/core/testingasync 函式已重新命名為 waitForAsync,以免混淆原生的 JavaScript async 語法。該函式已棄用,並將在以後的版本中移除。參閱 PR 37583

    The async function from @angular/core/testing has been renamed to waitForAsync in order to avoid confusion with the native JavaScript async syntax. The existing function is deprecated and will be removed in a future version. See PR 37583.

新的棄用

New Deprecations

位置

Area

API 或特性

API or Feature

可能會移除於

May be removed in

@angular/core/testing

waitForAsync 重新命名為 async

Rename async to waitForAsync

v13

新移除了已棄用的 API

New Removals of Deprecated APIs

從 11.0.0*開始,已經移除了以下 API:

The following APIs have been removed starting with version 11.0.0*:

套件

Package

API

替代品

Replacement

備註

Notes

@angular/routerNavigationExtras#preserveQueryParams

什麼也不用做

no action needed

NavigationExtras#preserveQueryParams 已從 @angular/router 移除。

NavigationExtras#preserveQueryParams has been removed from @angular/router.

@angular/coreCollectionChangeRecord

什麼也不用做

no action needed

CollectionChangeRecord 已從 @angular/core 移除。

CollectionChangeRecord has been removed from @angular/core.

@angular/coreViewEncapsulation.Native

什麼也不用做

no action needed

Angular 以前支援基於 v0 Shadow DOM Draft API 的檢視封裝模式 ViewEncapsulaion.Native。這些 API 已被最終的 Shadow DOM API 所取代,它透過 ViewEncapsulation.ShadowDom 進行啟用。關於此更改的背景資訊,請參閱 Web 元件更新:有更多時間升級到 v1 API了

Angular previously supported a view encapsulation mode ViewEncapsulaion.Native that was based on the v0 Shadow DOM Draft APIs. These APIs have been superceeded by the final Shadow DOM APIs, which are enabled via ViewEncapsulation.ShadowDom. For background information about this change, see Web Components update: more time to upgrade to v1 APIs.

Ivy 的功能和相容性

Ivy features and compatibility

從版本 9 開始,Angular Ivy 就是預設的渲染引擎。如果你還沒有聽說過 Ivy,你可以在 Angular Ivy 指南中閱讀更多相關資訊。

Since 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.

  • 在其他特性中,Ivy 在範本中引入了更全面的型別檢查。欲知詳情,請參閱範本型別檢查

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

  • 關於除錯的一般性指導以及與 Ivy 相關的小改動列表,請參閱 Ivy 相容性指南

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

  • 如需尋找如何不選用 Ivy 的幫助,請參閱此處的說明。

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