In angular (v5) how do I listen to my apps Redux state object changing?

前端 未结 2 1027
广开言路
广开言路 2021-01-15 18:17

I need to know how to create a listener e.g. I want to subscribe to the AppState changing.

Below is my current very basic service. I have a dispatch action on the vi

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-15 19:10

    angular-redux offers a very convenient way of selecting slices of your store with the @select() decorator.

    Let's say your IAppState would be:

    export interface IAppState {
      counter: number;
      auth: {token: string}; 
    }
    

    Then you can select the parts of your state like this:

    // variable name is equal to state property + $
    @select() counter$: Observable;
    @select() auth$: Observable<{token: string}>;
    
    // path to store slice
    @select(['auth', 'token']) token$: Observable;
    

    For further information, have a look at the select docs.

提交回复
热议问题