Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. // /client/src/app/app.service.ts
  2.  
  3. private tasksSubject = new ReplaySubject<Task[] | null>(1);
  4. private tasks: Task[] = [ {...}, {...} ];
  5.  
  6. public tasksUpdated$ = Observable<Task[] | null>;
  7.  
  8. constructor() {
  9. this.tasksUpdated$ = this.tasksSubject.asObservable();
  10. this.getAllTasks();
  11. }
  12.  
  13. private getAllTasks(tasks: Task[]): void {
  14. this.tasksSubject.next(customer);
  15. }
  16.  
  17. // /client/src/app/task/task.component.ts
  18. private allTasks: Task[] | null;
  19.  
  20. private tasksUpdatedSubscription: Subscription;
  21.  
  22. ngOnInit() {
  23. this.tasksUpdatedSubscription = this.taskService.tasksUpdated$
  24. .subscribe((tasks: Task[] | null) => {
  25. this.allTasks = tasks;
  26. });
  27. }
  28.  
  29. public ngOnDestroy() {
  30. this.tasksUpdatedSubscription.unsubscribe();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement