Angular 18 has been released with a major feature upgrade that is causing quite a bit of buzz in the developer community – zoneless upgrade! This new feature promises faster performance and better memory management by removing the need for Zone.js, the library that has been at the core of Angular’s change detection mechanism since its inception. In this tutorial, we will walk through the steps required to upgrade an existing Angular application to Angular 18 with the zoneless upgrade.
Step 1: Update Angular CLI
The first step in upgrading to Angular 18 is to update your Angular CLI to the latest version. You can do this by running the following command in your terminal:
npm install -g @angular/cli@latest
Step 2: Update Angular dependencies
Next, you will need to update the Angular dependencies in your project’s package.json file. Open the file and update the @angular/core, @angular/common, and @angular/compiler-cli dependencies to version 18.0.0:
"dependencies": {
...
"@angular/core": "^18.0.0",
"@angular/common": "^18.0.0",
"@angular/compiler-cli": "^18.0.0",
...
}
Then, run the following command in your terminal to install the updated dependencies:
npm install
Step 3: Remove Zone.js
The next step is to remove Zone.js from your project, as it is no longer needed with the zoneless upgrade. You can do this by running the following command:
npm uninstall zone.js
Step 4: Update main.ts file
With Zone.js removed, you will need to make some changes to your main.ts file to enable the zoneless upgrade. First, import the noopZone from @angular/core and use it to create a new NgZone instance without any zone:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { enableProdMode, ɵɵdefineInjector, Injectable, ɵsetClassMetadata } from '@angular/core';
import { ɵɵdefineInjectable, InjectableDef } from '@angular/core';
import { ɵɵinject, ɵɵcore } from '@angular/core';
import { ɵɵdefineInjectable, ɵsetClassMetadata, ɵɵdirectiveInject, ɵɵinject, ɵɵprovide, ɵɵdefineComponent, ɵɵtext } from '@angular/core';
import {noopZone} from '@angular/core';
platformBrowserDynamic()
.bootstrapModule(AppModule, {
ngZone: noopZone
})
.catch(err => console.error(err));
Step 5: Update zoneless configuration
Finally, you will need to update your project’s configuration file (angular.json) to enable the zoneless upgrade. Add the following configuration to the build section of your project:
"architect": {
"build": {
"configurations": {
"production": {
"zoneLess": true
}
}
}
}
With these steps completed, your Angular application should now be upgraded to Angular 18 with the zoneless upgrade. Enjoy the improved performance and memory management that this new feature provides!
Enjoy the new Angular 18 Zoneless support 😉One of the most convenient ways of writing zoneless applications is by using Signals. If you want to learn them, check out my ongoing Modern Angular With Signals Course – https://angular-university.io/course/angular-signals-course
great rundown as always
it has a conflict with provideClientHydration() — why?
I am still using angular 8. 😢
whan I migrate to provideExperimentalZonelessChangeDetection() my tests still want zone.js in angular block "test" in "polyfills": [here…]
I migrate from karma to web-test-runner but still cant run test without zone.js correct. And I check my tests – they doesnt use zone.js
How to difficult to listen you
Thanks for the helpful and easy-to-follow video! When I followed your instructions to refactor my app to zoneless, I am getting a ReferenceError: Zone is not defined. Any tips on how to resolve that?
Is it necessary that if object defined in signalstate will only have deepsignal property.. can we achieve that in component? Without using signalState .?
Great video. Thanks a lot!
Thanks! The only thing i don't like about signal, is that updating its value, involve this.intervalCounter.update(counter=>counter + 1)….instead of the concise this.intervalCounter++. Hopefully future angular will have a shortcut syntax for update of signal.
So, now I need to know how and when I have to update the page content manually? This seems like a step backwards, from my point of view it's a very expensive change, performance for me has never been a problem in my Angular applications…
So I am combing thru a few apps to prepare to go zoneless. All going well…but I am stumped as to what to do with my reactive forms. Will they continue to work? (haha I will soon find out eh?!)
angular feels like its made by dirty fixes to fix other dirty fixes.
you are quick, cool video thank you for sharing 🙂
I still need some time to wrap my mind around some things
What's the importance of it?
Still a simple hello world is 500kb
The Angular 18 Zoneless Change Detection isn't working with AngularFire v18, it produces error when you try to run your App (ReferenceError: Zone is not defined) and causes the App not to run at all… Any fix for that?
Thanks for sharing! I was so excited about the new release that I produced a video about it as well: https://youtu.be/1EAqguJY_kc
@AngularUniversity Thanks for switching to the VS Code dark theme 🤝, which I commented on Angular Signals video.
Vasco, what are your thoughts on the current Angular Material v18? I personally think that the colors, in some components, such as buttons are messed up, the default themes have applied a very strange use of colors, or should I say, have applied colorless colors