文章内容
2019/8/2 16:23:50,作 者: 黄兵
Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?
最近在页面跳转的时候,出现如下提示:
Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?
出现问题的原因:
在Angular之外触发导航,需要调用ngZone.run()重新进入Angular区域。
解决方案:
修改源代码如下:
import {Component, NgZone, OnInit} from '@angular/core'; constructor(private ngZone: NgZone, private router: Router) {} onClientAuthorization: (data) => { console.log('onClientAuthorization - you should probably inform your server about completed transaction at this point', data); this.showSuccess = true; this.cartSaveService.order_succeed(data, this.selectValueId).subscribe((res: any) => { if (res === 'success') { setTimeout(() => { this.ngZone.run(() => this.router.navigateByUrl('/cart/pay_result')).then(); }, 10); } }); },
参考资料:
1、"Navigation triggered outside Angular zone" warning in unit tests #25837
2、NgZone
黄兵个人博客原创。
转载请注明出处:黄兵个人博客 - Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?
评论列表