Angular 15 Features
Angular 15 Features
@Component({
standalone: true,
selector: 'photo-gallery',
imports: [ImageGridComponent],
template: `
… <image-grid [images]="imageList"></image-grid>
`,
})
export class PhotoGalleryComponent {
// component logic
}
bootstrapApplication(PhotoGalleryComponent);
2.Router and HttpClient tree-shakable standalone APIs
You can build a multi-route application using the new router standalone APIs! To
declare the root route you can use the following:
bootstrapApplication(AppComponent, {
providers: [
provideRouter(appRoutes)
]
});
The v15 release also includes a few new features for the image directive:
canActivate() {
return this.loginService.isLoggedIn();
}
}
const route = {
path: 'somePath',
canActivate: [MyGuardWithDependency]
};
With the new functional router guards, you can refactor this code down to:
const route = {
path: 'admin',
canActivate: [() => inject(LoginService).isLoggedIn()]
};
@Component({
standalone: true,
template: '...'
})
export default class LazyComponent { ... }
Before this change, to lazy load a standalone component you had to:
{
path: 'lazy',
loadComponent: () => import('./lazy-file').then(m => m.LazyComponent),
}
Now the router will look for a default export and if it finds it, use it
automatically, which simplifies the route declaration to:
{
path: 'lazy',
loadComponent: () => import('./lazy-file'),
}
7.Release MDC-based components to stable
We’re happy to announce the refactoring of the Angular material components based on
Material Design Components for Web (MDC) is now done! This change allows Angular to
align even closer to the Material Design specification, reuse code from primitives
developed by the Material Design team, and enable us to adopt Material 3 once we
finalize the style tokens.
import {MatLegacyButtonModule} from '@angular/material/legacy-button';
8.CDK Listbox
The Component Dev Kit (CDK) offers a set of behavior primitives for building UI
components. In v15 we introduced another primitive that you can customize for your
use case — the CDK listbox:
9.Improvements in the experimental esbuild support
Cleaner, Better Stack Traces
ng build --watch support, Sass, SVG template, and file replacement. The command for
upgrading the angular.json builder is:
"builder": "@angular-devkit/build-angular:browser-esbuild"
10.CLI improvements
In the Angular CLI we introduced support for standalone
stable APIs.
Now you can generate a new standalone component via
ng g component --standalone.
You can now specify your polyfills directly in angular.json in the polyfills
section:
"polyfills": [
"zone.js"
]
11.Router Now Auto-Unwarps Default Exports For Lazy Loading: It simplifies the
router functions by adding more enablement to reduce even more boilerplates. Here,
for lazy loading, the router will look for the default export, and if it gets
successful, it directly imports its lazy-file into the code.
Automatic Imports In-Language Support Service –
Quick Fix: Now, write your Angular code more confidently by making the most out of
the language service. You can use this feature to automatically import components
and their fixes in the template, which components are not used in a standalone
component or in a NgModule.
Improved Angular Components: The Angular components’ v15 covers a range of
accessibility enhancements, including effective contrast ratios, expanded touch
target sizes, and refined ARIA semantics. Furthermore, Angular components can have
their APIs to customize their density for a better theme customization experience.