Till now we have seen how to create store and update it. Now let's see how do we get values from it.
let's say we have state object as follows.
const state = {
username: '@angular/store'
}
To get that updated value we need to register with our state as follows.
import { Selector} from 'angular-store';
@Selector('username') $username: Observable<string>;
import { Selector} from 'angular-store';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'angular-store-lib'
@Selector('username') $username: Observable<string>;
}
constructor(private store: Store) {
this.$username.pipe().subscribe((lol) => {
// console.log('username', lol);
});
}
As you can see @Selector decorator returns Observable with respective payload.