简体   繁体   中英

http persist call outside Angular zone

I'm trying to figure out how NgZone works. Does the following example make sense?

persistData() {
  this.ngZone.runOutsideAngular(() => {
     this.http.callBackend...  // return value is not relevant
  });
}

I read that ever xhr call triggers the change detection. So this seems meaningful to me. Is it?

Yes it is, it means Angular won't run change detection when the callBackend returns.

But you need to make sure that you handle all the updates you are looking for on your own.

Angular uses zone.js . zone.js wraps all the asynchronous operations (including XHR change event which includes your case) and then trigger a change detection. If you have a LOT of async operations then change detection might occur to often and you'll feel it in ongoing performance, everything will be slow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM