gpt4 book ai didi

angular - 可观察到的 ExpressionChangedAfterItHasBeenCheckedError

转载 作者:太空狗 更新时间:2023-10-29 17:39:11 25 4
gpt4 key购买 nike

我正在尝试访问 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
});

}

在执行上面的代码时出现以下错误:-

ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'false'. Current value: 'true'

最佳答案

尝试使用

this._changeDetectionRef.detectChanges();

在你的方法结束时,

...不要忘记添加

private _changeDetectionRef : ChangeDetectorRef

作为拥有您方法的组件的构造函数的参数。

参见讨论 here

关于angular - 可观察到的 ExpressionChangedAfterItHasBeenCheckedError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46666437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com