With a regular observable, you only get the value when it changes, so if you want console.log to output the value you will need to use console.log in the subscription:
constructor( private store: Store<any> ) { this.count = this.store.select<any>(state => state.count); this.count.subscribe(res => console.log(res)); }
However, if you want to get the current value at any time, then what you need is a BehaviorSubject (which combines Observable and Observer in functions ... imports it from the rxjs library, just like you, Observable).
private count:BehaviorSubject<number> = new BehaviorSubject<number>(0); constructor( private store: Store<any> ) { let self = this; self.store.select<any>(state => self.count.next(state.count)); }
Then, anytime you want to get the current counter value, you call this.count.getValue() to change the value you would this.count.next(<the value you want to pass in>) . This should get what you are looking for.
Maarek
source share