I am trying to access a rest api inside ngOnit as given below:-
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. Previous value: 'false'. Current value: '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.
See discution here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With