How to use BehaviourSubjects to share data from API call between components in Angular?

前端 未结 6 535
甜味超标
甜味超标 2021-01-28 22:21

I am currently building an Angular application where I make a request to an api, and I map the repsonse to two different arrays. I can use this data in my app.components.t

6条回答
  •  别那么骄傲
    2021-01-28 22:50

    The simple way to go about this, would be to use BehaviorSubject. The documentation on this is comprehensive, I'm sure you can find it.

    To handle complex state in large applications, people use Redux. For Angular, there is NgRx.

    If updating state requires you to call an API as a side effect, use ngrx/effects

    https://ngrx.io/guide/effects

提交回复
热议问题