Suppose I have the following functions:
getUsers() {
return Observable.of(['Adam', 'Eve'])
}
getUserPets(user) {
return Observable.of(user === 'Adam' ? 'Adam pets' : 'Eve pets');
}
getUserKids(user) {
return Observable.of(user === 'Adam' ? 'Adam kids' : 'Eve kids');
}
I would like to create function fetching users, their pets, kids and returning all that data as single object. Something like:
getUsersData() {
// should return
// [
// { user: 'Adam', pets: 'Adam pets', kids: 'Adam kids' },
// { user: 'Eve', pets: 'Eve pets', kids: 'Eve kids' }
// ]
}
I tried to use combineLatest operator but my solution was really messy. What is the simpliest (or the most readable) way to implement such function?
sandbox: https://stackblitz.com/edit/angular-rspmy9?embed=1&file=app/app.component.ts