In Angular 9, the Ivy Compiler has been designed in such a way so that it can remove the unnecessary parts of the Angular which are not being used via tree-shaking structure and as a result, it will generate less code for each Angular component in compared to the previous versions. With these improvements, small-size applications and large applications can see the most dramatic changes in the application size.
In Angular 9, we can implement faster testing with the help of the Ivy renderer engine. The TestBed is one of the APIs used for testing any angular application. In the previous Angular version, it had defined as a get function called TestBed.get() which does not accept string value after Angular 8. This is one of the breaking changes in Angular 9. Since the Angular team dedicated to rollback in this new version as it always has a very powerful impact. To solve the type of safety problem, the Angular team provide a solution called TestBed.inject() and deprecated the get function.
Modules with Providers Support
This option is mainly for library owners. If we have used ModuleWithProvider before Angular 9, at that time we may or may not have been strongly typing it. But now, from this version, we have to always use the generic ModuleWithProviders<T> type to show our module type. In the earlier version, our declaration might be looks like as below -
Changes in Angular Forms
In Angular 9, there are some changes also make in the Angular Form Version. First of all, In Angular 9 <ngForm> is no longer exists as a form selector to use Angular Form. We need to use <ng-form> to access the Angular Form in our component. Secondly, FormsModule.withConfig has been removed and now we can use FormsModule directly.
Dependency Injection Changes in Core
In the case of dependency injection, Angular 9 comes with much more improvement and functionalities. So, when we will create an @Injectable service in Angular 9, we must choose whether it should be added to the injector. In addition to the previous root and module options, now we have two more additional options –
- platform – Mentioning providedIn: ‘platform’ option makes the service available in a special singleton platform injector which will be shared by all applications on the page.
- any - Mentioning providedIn: ‘any’ option provides a unique instance in every module (including lazy modules) that injects the token.
i18n Improvements
Angular as a JavaScript framework has been now totally supported by the internationalization and with the help of the Angular CLI, we can produce basis codes that will help us to create converter files so that we can develop an application in multiple languages. This method also further refactored by the Angular team on the Ivy engine to make it easier to implement compile-time inline.
Need for Faster Mobile Apps
As mobile usage is growing strongly around the world and the quarter of the website traffic is made up of smartphones and other mobile devices. A significant percentage of these mobile devices have access to web pages from slow internet connections. It's important to decrease downloadable resources and increase mobile user experience, but such improvements can be difficult. Ivy helps in speed application startup by reducing the size of JavaScript classes.
Service Worker Updates
In this Angular 9 version, for service workers, the deprecated versioned files option in the service worker asset group config has been removed. This means that your ngsw-config.json file that looked like this:
- "assetGroups": [
- {
- "name": "test",
- "resources": {
- "versionedFiles": [
- "/**/*.txt"
- ]
- }
- }
- ]
Now, in Angular 9 it looks like as below -
- "assetGroups": [
- {
- "name": "test",
- "resources": {
- "files": [
- "/**/*.txt"
- ]
- }
- }
- ]
How to Upgrade in Angular 9
To upgrade any existing Angular 8 or previous application to Angular 9, we need to perform the below steps –
- Angular 9 use TypeScript 3.7 so install TypeScript 3.7
- You need to use Node 12 or Later
- Now execute the upgrade command of Angular CLI -> ng update @angular/cli @angular/core
For getting better update experience, Angular recommended updating first to the latest version of Angular 8 with the below command -
- ng update @angular/cli@8 @angular/core@8
Then, we can run the update command of Angular 9 -
- ng update @angular/cli @angular/core
After a successful update, check the Angular version with the below command –
Conclusion
In this article, we discuss the new features of Angular 9. We also discussed some breaking changes in Angular 9 means which has been changed in comparison to the previous version of angular. Also, we discussed some new features about Angular 9. I hope, this article will help you. Any feedback or query related to this article is most welcome.