How to get current value of State object with @ngrx/store?

后端 未结 10 1503
失恋的感觉
失恋的感觉 2020-12-08 06:13

My service class, before calling a web service, needs to get a property called dataForUpdate from my state. Currently, I\'m doing it like this:



        
10条回答
  •  爱一瞬间的悲伤
    2020-12-08 06:43

    My Solution


    the State class in ngStore is an BehaviorSubject, so we can inject it, and use it's value property to get the latest value.

    constructor(private state:State...) {
    
    }
    
    someMethod() {
        // WHAT'S MORE: you can use your selector directly on it!
        let v = yourSelector(this.state.value);
    }
    

提交回复
热议问题