What Is New in Angular 6.0
Angular 6.0 is a major release focused on the toolchain and making it easier to move quickly with Angular in the future. This update brings the entire platform forward, including the core framework, Angular CLI, and Angular Material.
| Category | Key Changes |
|---|---|
| New Features | Angular Elements, Angular Material Starter Components, CLI Workspaces |
| Improvements | Faster Compiler (ngc), Tree Shakable Providers, RxJS 6.0 Update |
| Bug Fixes | Animation, Service Worker, Router, and i18n fixes |
| Deprecated | ngModel with reactive forms, HttpModule |
How does the new Angular CLI workspace model improve development?
The Angular CLI now uses a new workspace and library model with an angular.json file. This replaces the previous .angular-cli.json configuration. The new structure is designed to support multiple projects and libraries within a single workspace, which is a game-changer for monorepo development.
In practice, this means you can manage multiple applications and shareable libraries from one CLI context. The ng generate library command makes it straightforward to create and build reusable code. This matters because it streamlines the workflow for large-scale enterprise applications.
What are Angular Elements and why should I use them?
Angular Elements is a new feature that allows you to package Angular components as custom elements (web components). This lets you use Angular components in any HTML page, even non-Angular environments. It effectively bridges the gap between Angular and the native web platform.
You can create a component and use the createCustomElement() function to transform it into a standard custom element. This is powerful for incrementally upgrading legacy applications or embedding widgets into CMS-powered sites without a full framework bootstrapping process.
How does the RxJS 6 update affect my existing code?
Angular 6 now depends on RxJS 6, which introduced breaking changes to its import paths and API. The old way of importing from 'rxjs/Observable' is replaced by imports from 'rxjs'. Operators are now imported from 'rxjs/operators'.
To ease the migration, the RxJS team provides a backward-compatibility layer and a TSLint-enabled update tool. Running rxjs-5-to-6-migrate will automatically refactor most of your code. This change results in smaller application bundles and a more modular RxJS library.
What are tree-shakable providers and how do they work?
Tree-shakable providers are a new way to define services using the providedIn property. Instead of adding the service to a module's providers array, you now declare it directly in the @Injectable decorator.
@Injectable({
providedIn: 'root'
})
export class MyService { }
This tells the Angular compiler that the service should be bundled only if it's actually used by the application. If nothing injects MyService, it gets dropped during the build process, leading to smaller final bundle sizes.
FAQ
Do I have to completely rewrite my services to use the new providedIn syntax?
No, the old method of registering services in NgModules still works. The new syntax is optional but recommended for better tree-shaking and to make services available without requiring a specific NgModule.
Is the switch from HttpModule to HttpClientModule mandatory in v6?HttpModule is now deprecated. While it still functions, you should migrate to HttpClientModule for all new development as it offers a more powerful and flexible API with built-in JSON parsing and interceptors.
What's the deal with the new ng update command?ng update is a powerful new CLI command that analyzes your package.json and uses its knowledge of the Angular ecosystem to recommend and automatically apply updates to your dependencies and code.
I use animations; will I be affected by the changes?
Yes, there are breaking changes to animation. The AnimationTriggerEvent interface has been removed. Its functionality is now covered by the standard AnimationEvent interface from @angular/animations.
Can I still use the old .angular-cli.json file?
No. When you update your project using ng update, the CLI will automatically migrate your configuration to the new angular.json format. The old file is no longer supported.