Random Angular Tips
·1 min
Table of Contents
How to chain observables #
If observable2
(getAuthorizedApplications
) depends on a finished observable1
(getSubjectToken
) you can utilize mergeMap
from rxjs
:
class SomeClass {
...
onCredentials(credentials: Credentials) {
this.auth
.getSubjectToken(credentials)
.pipe(
map((res) => res.headers.get('X-Subject-Token') ?? ''),
tap((subjectToken) => {
localStorage.setItem('X-Subject-Token', subjectToken);
}),
mergeMap((subjectToken) => {
return this.auth.getAuthorizedApplications(subjectToken);
})
)
.subscribe((res) => console.log(res));
}
...
}