Introduction
Tree-shakable router
You can build multiple routes applications with the new router standalone API.
Define the root routes in app.routes.ts
, and use loadChildren
to load the lazy routes.
1 | // app.routes.ts |
Define the lazy routes in lazy.routes.ts
.
1 | // lazy.routes.ts |
Provide the router in file main.ts
.
1 | // main.ts |
The benefit of provideRouter
is that it is tree-shakable.
Directive composition API
这个我没太看懂,需要进一步研究它的来历。
1 | ({ |
NgOptimizedImage
NgOptimizedImage
is a new directive that optimizes images for the web.
First, import NgOptimizedImage
in your component.
1 | import { NgOptimizedImage } from '@angular/common'; |
Then, replace src
in img tag with ngSrc
.
1 | <img [ngSrc]="url" alt="image"> |
Functional router guards.
You can now use functional router guards.
Before:
1 | providedIn: 'root' }) ({ |
After:
1 | const route = { |
Route unwraps default imports
Before:
You need .then
to unwrap the default import.
1 | { |
Now: with the default export enabled, you can directly use the default import.
1 | { |
You must use default export
in the lazy file.
1 | ({ |
Automatic imports in language service.
When you type a component selector in the template, the language service will prompt to import the component for you.
CLI improvements
Generate standalone components with the following command
1 | ng g component --standalone |
Simplify the output of the ng serve
command.
- Remove File
test.ts
,polyfills.ts
, andenvironments
- Specify polyfills in
angular.json
1
2
3"polyfills": [
"zone.js"
]
Global format for Date
pipe
1 | bootstrapApplication(AppComponent, { |
Deprecations
providedIn: 'any'
is deprecated. UseprovidedIn: 'root'
instead.providedIn: NgModule
is deprecated. UseprovidedIn: 'root'
orprovidedIn: NgModule
instead.