Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { Store, select } from '@ngrx/store';
  3. import { selectClub, selectSortState } from './store/clubs.selector';
  4. import { RequestClubsAction, SortClubsAction } from './store/clubs.actions';
  5. import { Observable } from 'rxjs';
  6. import { ClubsState, SortState } from './store/clubs.state';
  7.  
  8. @Component({
  9. selector: 'app-clubs',
  10. template: `
  11. <app-table
  12. [clubs]="clubs$ | async"
  13. [sortState]="sortState$ | async"
  14. (doSort)="sort($event)"
  15. ></app-table>
  16. `
  17. })
  18. export class ClubsComponent implements OnInit {
  19. clubs$: Observable<ClubsState[]>;
  20. sortState$: Observable<SortState>;
  21.  
  22. constructor(private store: Store<any>) {}
  23.  
  24. ngOnInit() {
  25. this.store.dispatch(new RequestClubsAction());
  26.  
  27. this.clubs$ = this.store.pipe(select(selectClub));
  28. this.sortState$ = this.store.pipe(select(selectSortState));
  29. }
  30.  
  31. sort(event): void {
  32. this.store.dispatch(new SortClubsAction({ sort: event }));
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement