|
| 1 | +# Update Angular to v16 |
| 2 | + |
| 3 | +<!-- NOTE to writers: When creating the topic for the next version, --> |
| 4 | +<!-- remember to update the redirect link in angular/aio/firebase.json --> |
| 5 | +<!-- To update the redirect link in angular/aio/firebase.json: --> |
| 6 | +<!-- 1. Search for the entry in firebase.json with "source": "guide/update-to-latest-version" --> |
| 7 | +<!-- 2, Update the destination value to refer to the new guide's URL --> |
| 8 | +<!-- --> |
| 9 | + |
| 10 | +This topic provides information about updating your Angular applications to Angular version 16. |
| 11 | + |
| 12 | +For a summary of this information and the step-by-step procedure to update your Angular application |
| 13 | +to v16, see the [Angular Update Guide](https://update.angular.io). |
| 14 | + |
| 15 | +The information in the [Angular Update Guide](https://update.angular.io) and this topic is |
| 16 | +summarized from these changelogs: |
| 17 | + |
| 18 | +* [angular/angular changelog](https://github.com/angular/angular/blob/main/CHANGELOG.md) |
| 19 | +* [angular/angular-cli changelog](https://github.com/angular/angular-cli/blob/main/CHANGELOG.md) |
| 20 | +* [angular/components changelog](https://github.com/angular/components/blob/main/CHANGELOG.md) |
| 21 | + |
| 22 | +Information about updating Angular applications to v15 is archived at |
| 23 | +[Update to version 15](/guide/update-to-version-15). |
| 24 | + |
| 25 | +<a id="new-features"></a> |
| 26 | + |
| 27 | +## Feature highlights in Angular v16 |
| 28 | + |
| 29 | +For a more comprehensive list of new features, see the |
| 30 | +[Angular blog post on the update to v16](https://blog.angular.io). |
| 31 | + |
| 32 | +<!-- markdownLint-disable MD001 --> |
| 33 | + |
| 34 | +#### Angular Signals developer preview |
| 35 | + |
| 36 | +This release includes the first developer preview of Angular's new reactivity primitives: `signal`, |
| 37 | +`computed`, and `effect`. See the [signals guide](/guide/signals) for details and the |
| 38 | +[Angular Signals RFC](https://github.com/angular/angular/discussions/49685) for more background. |
| 39 | + |
| 40 | +#### Enhanced hydration developer preview |
| 41 | + |
| 42 | +Previously, when Angular bootstrapped on a page that was server-side rendered or compile-time |
| 43 | +pre-rendered, the framework would discard any existing DOM nodes and re-render from scratch. With |
| 44 | +v16's enhanced hydration support, you can opt into Angular reusing these existing DOM nodes. This |
| 45 | +developer preview feature can improve page load performance in many scenarios. See the full |
| 46 | +[hydration guide](/guide/hydration) for details. |
| 47 | + |
| 48 | +### Faster builds with the esbuild developer preview |
| 49 | + |
| 50 | +v16 brings you the developer preview of Angular CLI's new builders based on |
| 51 | +[esbuild](https://esbuild.github.io). This new architecture can significantly improve build times in |
| 52 | +many scenarios. This preview additionally includes integration with [Vite](https://vitejs.dev) |
| 53 | +powering the CLI's development server. |
| 54 | + |
| 55 | +You can try this new build setup by updating your `angular.json`: |
| 56 | + |
| 57 | +```json |
| 58 | +"architect": { |
| 59 | + "build": { |
| 60 | + "builder": "@angular-devkit/build-angular:browser-esbuild", |
| 61 | +``` |
| 62 | + |
| 63 | +### Standalone component migration and scaffolding |
| 64 | + |
| 65 | +To support developers transitioning their apps to standalone APIs, Angular v16 includes migration |
| 66 | +schematics and a standalone migration guide. These tools dramatically reduce the effort required to |
| 67 | +move your code to standalone components, directives, and pipes. Visit the |
| 68 | +[standalone migration guide](/guide/standalone-migration) for details. |
| 69 | + |
| 70 | +You can now also generate new Angular applications with standalone components by running: |
| 71 | + |
| 72 | +```sh |
| 73 | +ng new --standalone |
| 74 | +``` |
| 75 | + |
| 76 | +### Required inputs |
| 77 | + |
| 78 | +You can now mark component and directive inputs as _required_: |
| 79 | + |
| 80 | +```typescript |
| 81 | +export class ColorPicker { |
| 82 | + @Input({ required: true }) defaultColor: string; |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +If a template includes a component without specifying all of its required inputs, Angular reports |
| 87 | +an error at build time. |
| 88 | + |
| 89 | +<a id="breaking-changes"></a> |
| 90 | + |
| 91 | +## Highlighted breaking changes in Angular v16 |
| 92 | + |
| 93 | +For a comprehensive list of breaking changes, see the full changelogs on GitHub. |
| 94 | + |
| 95 | +<a id="v16-bc-01"></a> |
| 96 | + |
| 97 | +### Angular v16 requires node.js version v16 or v18 |
| 98 | + |
| 99 | +Angular requires node.js v16 or v18. [PR #47730](https://github.com/angular/angular/pull/49255) |
| 100 | + |
| 101 | +See [Version compatibility](/guide/versions) for full version compatibility details. |
| 102 | + |
| 103 | +<a id="v16-bc-02"></a> |
| 104 | + |
| 105 | +### Angular v16 requires TypeScript version 4.9 or later |
| 106 | + |
| 107 | +Angular v16 no longer supports TypeScript versions older than 4.9. [PR #49155](https://github.com/angular/angular/pull/49155) |
| 108 | + |
| 109 | +See [Version compatibility](/guide/versions) for full version compatibility details. |
| 110 | + |
| 111 | +<a id="v16-bc-03"></a> |
| 112 | + |
| 113 | +### Angular Compatibility Compiler (ngcc) has been removed |
| 114 | + |
| 115 | +The Angular Compatibility Compiler (ngcc) was a build tool that facilitated compatibility between |
| 116 | +Angular's previous compiler and rendering architecture (View Engine) and its new architecture (Ivy). |
| 117 | + |
| 118 | +View Engine was removed in Angular v13, and v16 finally removes ngcc. As a result, Angular |
| 119 | +libraries built with View Engine cannot be used in Angular v16+. |
| 120 | + |
| 121 | +<a id="v16-bc-04"></a> |
| 122 | + |
| 123 | +#### Angular Package Format changes |
| 124 | + |
| 125 | +The Angular Package Format (APF) has been updated |
| 126 | +with the following changes: |
| 127 | + |
| 128 | +* Flattened ESM 2015 (FESM2015) outputs have been removed. |
| 129 | +* EcmaScript 2020 outputs have been updated to EcmaScript 2022 (including the flattened output). |
| 130 | + |
| 131 | +See [Angular Package Format](/guide/angular-package-format) for background. |
| 132 | + |
| 133 | +<a id="v16-bc-06"></a> |
| 134 | + |
| 135 | +#### `ReflectiveInjector` has been removed |
| 136 | + |
| 137 | +The ReflectiveInjector and related symbols were removed. Please update the code to avoid references |
| 138 | +to the ReflectiveInjector symbol. Use `Injector.create` to create an injector instead. |
| 139 | + |
| 140 | +<a id="v16-bc-07"></a> |
| 141 | + |
| 142 | +#### Updated behavior for `Router.createUrlTree` |
| 143 | + |
| 144 | +Tests which mock `ActivatedRoute` instances may need to be adjusted because Router.createUrlTree now |
| 145 | +does the right thing in more scenarios. This means that tests with invalid/incomplete ActivatedRoute |
| 146 | +mocks may behave differently than before. Additionally, tests may now navigate to a real URL where |
| 147 | +before they would navigate to the root. Ensure that tests provide expected routes to match. There is |
| 148 | +rarely production impact, but it has been found that relative navigations when using |
| 149 | +an `ActivatedRoute` that does not appear in the current router state were effectively ignored in the |
| 150 | +past. By creating the correct URLs, this sometimes resulted in different navigation behavior in the |
| 151 | +application. Most often, this happens when attempting to create a navigation that only updates query |
| 152 | +params using an empty command array, for |
| 153 | +example `router.navigate([], {relativeTo: route, queryParams: newQueryParams})`. In this case, |
| 154 | +the `relativeTo` property should be removed. |
| 155 | + |
| 156 | +<a id="deprecations"></a> |
| 157 | + |
| 158 | +## Deprecations highlights in Angular v16 |
| 159 | + |
| 160 | +These APIs remain available in v16, but may be removed in future versions as described by Angular's |
| 161 | +[deprecation practices](/guide/releases#deprecation-practices). |
| 162 | + |
| 163 | +To maintain the reliability of your Angular application, always update your application as soon as |
| 164 | +practicable. |
| 165 | + |
| 166 | +| Removed | Replacement | Details | |
| 167 | +|:-------------------------------------------------------------------------------------|:------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 168 | +| <a id="v16-dp-01"></a>Class and `InjectionToken` router guards and resolvers | See details | Class and `InjectionToken` guards and resolvers are deprecated. Instead, write guards as plain JavaScript functions and inject dependencies with `inject` from `@angular/core`.<br>[PR #47924](https://github.com/angular/angular/pull/47924) | |
| 169 | +| <a id="v16-dp-02"></a>The `ripple` properties of several Angular Material components | None | The `ripple` property of `MatButton`, `MatCheckbox`, `MatChip` is deprecated. This change moves ripples to being a private implementation detail of the components. | |
| 170 | + |
| 171 | +@reviewed 2023-05-03 |
0 commit comments