Angular and ZoneLess
Don't care if you use Angular 14, 15...19; your apps are still under the Zone.js umbrella. Maybe you feel your Angular apps work well, but under the hood, with Zone.js, Angular needs to iterate over the entire DOM tree, impacting app performance. This happens because Zone.js uses mocking patches to listen to DOM events and notify Angular when an event is triggered in the app, because Zone.js doesn't know the state of your application or what caused changes, Angular has to check every node in the app.
After moving to a zoneless approach, we can use ChangeDetectorRef.markForCheck (AsyncPipe), ComponentRef.setInput, or even a Signal to react to changes or new lifecycle hooks like afterNextRender, or `afterRender`.
Moving To ZoneLess
First, create a new project using Angular 19 CLI ng new my-zoneless-app :
ng new my-zoneless-app ✔ Which stylesheet format would you like to use? Sass (SCSS) [ https://sass-lang.com/documentation/syntax#scss ] ✔ Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)? no CREATE my-zoneless-app/README.md (1476 bytes) CREATE my-zoneless-app/.editorconfig (314 bytes) CREATE my-zoneless-app/.gitignore (587 bytes) CREATE my-zoneless-app/angular.json (2800 bytes) CREATE my-zoneless-app/package.json (1046 bytes) CREATE my-zoneless-app/tsconfig.json (915 bytes)
Remove Zone.js from your project by running npm uninstall zone.js command.
npm uninstall zone.js
Edit your angular.json file to remove zone.js and zone.js/testing from both to remove it from the build. Projects that use explicit polyfills.ts file should remove import 'zone.js'; and import 'zone.js/testing'; from the file.
To activate our angular without zonejs, open app.config.ts file, in the providers sections, remove provideZoneChangeDetection({ eventCoalescing: true }) and add provideExperimentalZonelessChangeDetection()
Note provideExperimentalZonelessChangeDetection is experimental
The app.config looks like:
import {ApplicationConfig, provideExperimentalZonelessChangeDetection, provideZoneChangeDetection} from '@angular/core'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; export const appConfig: ApplicationConfig = { providers: [ provideExperimentalZonelessChangeDetection(), provideRouter(routes)] };
Save your changes run ng serve tada!! our app works just like before but without NgZone! ?
That is perfect, but maybe I want to create zoneless by default. No worries; the Angular CLI allows you to do it with a flag.
Create a Zone-Less App by Default?
Create a zone-less app directly using the Angular CLI, create a new project with the --experimental-zoneless flag:
ng new fastweb --experimental-zoneless
The --experimental-zoneless flag sets up a zone-less project out of the box, configuring it to work without Angular Zones.
Sadly but in. Angular 19.0.1 we need to remove "zone.js" package manually by run npm uninstall zonejs
After that, we are ready to build zoneless apps in Angular 19!
Recap
We learned how to remove zone.js existing applications or create by default using the CLI flag, I hope you start to build your apps without ZoneJS. ?
SourceCode: https://github.com/danywalls/zoneless-angular-app
The above is the detailed content of Angular and ZoneLess. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.
