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

后端 未结 10 1528
失恋的感觉
失恋的感觉 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:44

    Not strictly a direct answer to the question, but I found this page looking for how to retrieve a single value from the store.

    To achieve this, you can inject the State object from @ngrx/store as shown below:

    import { State } from '@ngrx/store';
    
    constructor (private state: State) {
        let propertyValue = state.getValue().path.to.state.property;
    }
    

    The state object holds the current state in a private _value property, accessed by the .getValue() method.

提交回复
热议问题