Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // /client/src/app/app.service.ts
- private tasksSubject = new ReplaySubject<Task[] | null>(1);
- private tasks: Task[] = [ {...}, {...} ];
- public tasksUpdated$ = Observable<Task[] | null>;
- constructor() {
- this.tasksUpdated$ = this.tasksSubject.asObservable();
- this.getAllTasks();
- }
- private getAllTasks(tasks: Task[]): void {
- this.tasksSubject.next(customer);
- }
- // /client/src/app/task/task.component.ts
- private allTasks: Task[] | null;
- private tasksUpdatedSubscription: Subscription;
- ngOnInit() {
- this.tasksUpdatedSubscription = this.taskService.tasksUpdated$
- .subscribe((tasks: Task[] | null) => {
- this.allTasks = tasks;
- });
- }
- public ngOnDestroy() {
- this.tasksUpdatedSubscription.unsubscribe();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement