I am using @fromState to get values in my service from store similar to this, but it is just the undefined or default value:
import { DI, IEventAggregator, resolve } from 'aurelia';
import { IRouter, IRouteableComponent } from '@aurelia/router';
import { fromState, IStore } from '@aurelia/state';
import { State } from './state.types';
export class Search implements IRouteableComponent {
readonly ea: IEventAggregator = resolve(IEventAggregator);
private router: IRouter = resolve(IRouter);
@fromState<State>(state => {
return state.query;
})
query: string;
constructor(@IStore readonly store: IStore<{}, { type: string; value: string }>) {
this.store = store;
}
method() {
console.log('query in store', this.query)
}
}
export const ISearch = DI.createInterface<ISearch>('ISearch', x => x.singleton(Search));
// Export type equal to the class to create an interface
export type ISearch = Search;