Guest User

Untitled

a guest
Jun 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2. import { Store, select, Action } from '@ngrx/store';
  3. import { IApplicationState, IFormState } from './state/application-state';
  4.  
  5. @Component({
  6. selector: 'app-root',
  7. templateUrl: './app.component.html',
  8. styleUrls: ['./app.component.css']
  9. })
  10. export class AppComponent {
  11.  
  12. public formState: IFormState;
  13.  
  14. constructor(private store: Store<IApplicationState>) {
  15. // Subscribe to the newest version of the formState:
  16. this.store.pipe(select(e => e.form)).subscribe(fs => {
  17. this.formState = fs;
  18. });
  19. }
  20.  
  21. onFormActions($event: Action[]) {
  22. // whenever form (child) component emits event with actions as payload, dispatch them
  23. const actions = $event;
  24. actions.forEach(this.store.dispatch.bind(this.store));
  25. }
  26.  
  27. }
Add Comment
Please, Sign In to add comment