I am learning more about Angular and I am trying to run a method after I change a property. This is my code
isLoading = false;
ngOnInit() {
this.isLoading = true;
this._myService.getContent().subscribe(
(response: IContent) => {
this.isLoading = false;
this.doSomething();
// console.log(response);
},
err => {
this.isLoading = false;
this.doSomething();
console.log(err);
}
);
}
doSomething() {
console.log('some thing')
}
And with this I want to execute doSomething() after isLoading is set to false (like putting for example .then(() => {this.doSomething()}) after setting). I know i can put doSomething() in timeout like
setTimeout(() => this.doSomething(),10);
and that will work but i think there is a better way. I have searched for solution and found about ChangeDetectorRef which i am not sure on how to implement it on this case. There also might be a different approach with which i am not familiar.