angular-store
  • @angular/store
  • State
  • Reducer
  • Action
  • Dipatch
  • Selector
  • MISCELLANEOUS
    • Methods
Powered by GitBook
On this page

Selector

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'
}

Now, whenever there's a change in value of username we would like to receive updated value.

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.

PreviousDipatchNextMethods

Last updated 6 years ago