Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?

后端 未结 4 1166
迷失自我
迷失自我 2020-12-25 10:42

I am using Angular 7 and facing an issue => after login the API GET calls successfully and the component receiving data too, but UI is not displaying that data.

Whe

4条回答
  •  独厮守ぢ
    2020-12-25 11:09

    If i talk from top then meaning of the this warning is that event is trigger outside of zone i.e. if you know about zones or also called execution context which angular is used for change detection and UI rendering. so while navigration it is expected by the angular to re renderer the UI but it is not happening here that's the problem you are facing. so it throw this warning because angular process the change detection and UI rendering when the code executed lies inside of angular zone.

    But actually This warning comes when you trying to call the router navigration inside the subscribe method.

    Put your router navigation call outside of subscribe method and it will not throw this warning again. and you will see the expected UI after navigation.

    for more info about zones read and watch the video mention below:-

    https://blog.thoughtram.io/angular/2017/02/21/using-zones-in-angular-for-better-performance.html#running-outside-angulars-zone

    https://www.youtube.com/watch?v=3IqtmUscE_U&t=150

提交回复
热议问题