az-zoneless v0.0.7
az-zoneless
A set of directive and utilities to manage an angular zoneless app.
Using this library you can go completly zoneless and still support 3rd party libraries like @angular/material.
This library will solve the following:
- Angular material components without zone.js
- Issue on angular material zoneless
- Issue on angular material zoneless
Warning: This package is experimental
Installation
npm i az-zonelessIn your AppModule add the ZonelessModule to the imports array.
import { ZonelessModule } from 'az-zoneless'
@NgModule({
declarations: [
...
],
imports: [
...,
ZonelessModule
],
bootstrap: [AppComponent]
})
export class AppModule {
}Set your app to be zoneless
This library is meant to be used in an angular running in zoneless mode.
To make angular work without Zone.js please do the following:
- from the
polyfills.tscomment out the line whereZone.jsis imported
// import 'zone.js'; // Included with Angular CLI.- in the
main.tsyou need to tell angular to not work withZone.js
platformBrowserDynamic()
.bootstrapModule(AppModule, {
ngZone: "noop",
})
.catch((err) => console.error(err));Lecture about using angular in zoneless
Here is a lecture where I explain about angular in zoneless mode
Events
- After using the library, make sure to not use the regular events:
<!-- Do not use the regular events -->
<button (click)="doSomething()"></button>These events will still work but they are less performent.
- To improve performance and really take advantage of the fact that you are zoneless, please use the events like this:
<button (azClick)="doSomething()"></button>- In case you do decide to run angular with
Zone.jsthe library supplies you with an event that will run outside the angular zone.
<!-- the doSomething method will not trigger change detection and will run outside the angular zone -->
<button (azClick.zoneless)="doSomething()"></button>Directives
If you are afraid to remove zone.js, we also supply with directives that will allow you to incrementally transition your app to be zoneless.
Instead of removing zone.js completly, you can run part of your component tree outside zone.js
azZoneLess
With this directive you can run part of your component tree outside zone.js.
This will work only if you did not remove Zone.js
<div>
<h1>This part is inside zonejs</h1>
<button (click)="doSomething()">
clicking this will run change detection
</button>
<div *azZoneLess>
<h1>This part is outside zonejs</h1>
<button (click)="doSomething()">
clicking this will run outside the zone and will only update is you call
ChangeDetectorRef.detectChanges()
</button>
</div>
</div>azZoneFull
If you used the azZoneLess you can go back to running in angular zone using the azZoneFull directive.
This directive will only work if you did not remove Zone.js.
<div>
<h1>This part is inside zonejs</h1>
<button (click)="doSomething()">
clicking this will run change detection
</button>
<div *azZoneLess>
<h1>This part is outside zonejs</h1>
<button (click)="doSomething()">
clicking this will run outside the zone and will only update is you call
ChangeDetectorRef.detectChanges()
</button>
<div *azZoneFull>
<!-- This will return us back to the zone.js -->
<button (click)="doSomething()">This runs in the zone.js</button>
</div>
</div>
</div>