I have a service that makes some http call to a rest api. On my component I have a subscribe to it. How can I update the data on the subscribe without having to make a new call to the service?
相关问题
- Angular RxJS mergeMap types
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- How to update placeholder text in ng2-smart-table?
- How to instantiate Http service in main.ts manuall
- Angular: ngc or tsc?
相关文章
- angular脚手架在ie9+下兼容问题
- angular 前端项目 build 报错 "Cannot find module 'le
- Angular Material Stepper causes mat-formfield to v
- After upgrade to Angular 9 cannot find variable in
- is there any difference between import { Observabl
- Suppress “Circular dependency detected” suppress w
- How can you get current positional information abo
- Angular material table not showing data
The question is not quite clear, but I think I can infer enough to hopefully offer an answer.
Let's assume you have an observable of a
User
object that has anOrganizationId
property on it, and you want an observable of theOrganization
object associated with thatOrganizationId
. You want it to update when the user updates, right?This is what you would want to use the
flatMap
operator for. Assume ourorganizationService
has abyId$
method that takes in theOrganizationId
and returns an observable from thehttp.post()
method.You can think of
flatMap
as similar tomap
in that it will take one value, and turn it into another based on the callback that you pass to it. The difference is that if you used the normalmap
in this way, you would end up with an observable of an observable.flatMap
will unwrap the observable that is returned to it so you just have an observable of your desired object.