[英]ExpressionChangedAfterItHasBeenCheckedError with observable
I am trying to access a rest api inside ngOnit as given below:- 我正在尝试访问ngOnit中的rest api,如下所示: -
ngOnInit(): void {
this.myModel = new myModel ();
Observable.forkJoin(
this.myService.getdata(),
this.myService2.getData2(id)
).subscribe(
data => {
this.data1 = data[0];
this.data2 = data[1];
},
err => { console.error(err); },
() => {
//other work
});
}
on executing the above code i am getting below error:- 在执行上面的代码我得到以下错误: -
ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.
错误:ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后发生了变化。 Previous value: 'false'.
上一个值:'false'。 Current value: 'true'
当前价值:'true'
try to use 试着用
this._changeDetectionRef.detectChanges();
at the end of your method , 在你的方法结束时,
... not forgetting to add ......别忘了补充
private _changeDetectionRef : ChangeDetectorRef
as parameter of the constructor of the Component owning your method. 作为拥有您的方法的Component的构造函数的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.