Ioniconf 2022 logo

Uniting our global community of Ionic developers and contributors. May 25, 2022.

DocsPluginsCLI

Using Angular with Capacitor

NgZone

Capacitor plugin event listeners run outside of Angular’s NgZone execution context. Contain handler logic within an NgZone.run block to ensure Angular’s change detection is triggered:

constructor(private ngZone: NgZone) { }

async ngOnInit() {
  Network.addListener("networkStatusChange", (status) => {
    this.ngZone.run(() => {
      // This code will run in Angular's execution context
      this.networkStatus = status.connected ? "Online" : "Offline";
    });
  });
}
Previous
<- Ads
Next
Automated Configuration ->
Contribute ->