Is there a clever way to check if api get loaded before any operation on the object which comes from the backend is done?
Example:
ngOnInit() {
this.guideService.getAll()
.subscribe(res => {
this.guides = res;
});
}
...and
checkIfSaveButtonCanBeDisabled(){
console.log('checkIfSaveButtonCanBeDisabled');
if(this.guides){
for (let i = 0; i < this.guides.length; i++) {
if(!this.guides[i].confirm){
return false;
}
}
return true;
}
return false;
}
and without if
statement if(this.guides){}
I get this.guides.length is undefined
. The case is quite important because there could be other examples in project with similar case.