简体   繁体   English

具有可观察性的ExpressionChangedAfterItHasBeenCheckedError

[英]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的构造函数的参数。

See discution here 请参阅这里的讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 角度4 ExpressionChangedAfterItHaHasBeenCheckedError具有可观察到的但不能保证 - Angular 4 ExpressionChangedAfterItHasBeenCheckedError with observable but not promise ExpressionChangedAfterItHasBeenCheckedError - ExpressionChangedAfterItHasBeenCheckedError Angular 具有未定义可观察对象的应用程序不会导致 ExpressionChangedAfterItHasBeenCheckedError 错误,但它似乎应该? - Angular app with undefined observable does not cause ExpressionChangedAfterItHasBeenCheckedError Error but it seems like it should? ExpressionChangedAfterItHasBeenCheckedError:检查后表达式已更改 - 如何在可观察值更改后更新模板 - ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked - How to update template after Observable Value change ngIf ExpressionChangedAfterItHasBeenCheckedError - ngIf ExpressionChangedAfterItHasBeenCheckedError 获取ExpressionChangedAfterItHasBeenCheckedError - Getting ExpressionChangedAfterItHasBeenCheckedError ExpressionChangedAfterItHasBeenCheckedError解决方法 - ExpressionChangedAfterItHasBeenCheckedError workaround ExpressionChangedAfterItHasBeenCheckedError 解释 - ExpressionChangedAfterItHasBeenCheckedError Explained ngOnInit中的ExpressionChangedAfterItHasBeenCheckedError - ExpressionChangedAfterItHasBeenCheckedError in ngOnInit ngClass 的 ExpressionChangedAfterItHasBeenCheckedError - ExpressionChangedAfterItHasBeenCheckedError with ngClass
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM