Here's a function I have that needs some adjustment:
combineLatest([this.contact$, this.account$]).pipe(
map((res) => {contacts = res[0], account = res[1]})).subscribe()
I am facing an issue where the contact$ selector is sometimes empty. If it is empty, I need to call a service to populate the store. I attempted a fix as shown below, but it does not work as intended. Here is an example of what I want to achieve:
combineLatest([this.contact$, this.account$]).pipe(
map((res) => {
if(res[0].length === 0) {
this.getContacts()
}
contacts = res[0];
account = res[1]}
).subscribe()
getContacts() {
this.myService.getContacts().subscribe(res => {
this.store.dispatch(myAction.addContacts({contacts: res}))
})
}