Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

zonejs - 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?

question from:https://stackoverflow.com/questions/65941208/http-persist-call-outside-angular-zone

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...