When calling an observable that takes some time to resolve, I found myself needing to add a condition to check for a valid result. The current implementation seems functional, but I can't help feeling there might be a better way to handle this.
Here's the code snippet:
this.store.select(state => this.list = state.list)
.subscribe(result => {
//Without checking if result exists, it throws here undefined, only solution found so far is to add the check below
if (result) {
console.log('result is loaded');
this.copyOfList = [...this.list];
for (const item of result) {
this.itemCategories(item.category);
}
}
});