我正在尝试访问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
});
}
Run Code Online (Sandbox Code Playgroud)
在执行上述代码时,我得到以下错误:-
错误错误:ExpressionChangedAfterItHasBeenCheckedError:检查表达式后,表达式已更改。先前的值:“ false”。当前值:“ true”
尝试使用
this._changeDetectionRef.detectChanges();
Run Code Online (Sandbox Code Playgroud)
在你的方法结束时,
...不要忘记添加
private _changeDetectionRef : ChangeDetectorRef
Run Code Online (Sandbox Code Playgroud)
作为拥有您的方法的组件的构造函数的参数。
请参阅此处的讨论
| 归档时间: |
|
| 查看次数: |
1656 次 |
| 最近记录: |