import { TaskListComponent } from './../task-list/task-list.component';
import { Component, OnInit, ViewChild } from '@angular/core';
import { Task, TaskService } from './../../core/core.module';

@Component({
  selector: 'app-task-dashboard',
  templateUrl: './task-dashboard.component.html',
  styleUrls: ['./task-dashboard.component.scss']
})
export class TaskDashboardComponent implements OnInit {
  @ViewChild(TaskListComponent) taskList: TaskListComponent;
  
  tasks$;

  constructor(private taskService: TaskService) { }

  ngOnInit() {
    this.updateTaskList();
  }

  taskReceived(task){
    this.taskService.upsert(task).subscribe(r => {
      this.updateTaskList();
    });
  }

  updateTaskList(){
    this.tasks$ = this.getTasks();
  }

  deleteTask(task: Task) {
    this.tasks$ = this.taskService.remove(task).switchMap(_ => this.getTasks());
  }

  getTasks(){
    return this.taskService.getTasks().map(tasks => tasks.sort((a, b) => a.tag > b.tag ? +1 : -1));
  }
}

import { Component, OnInit } from '@angular/core';
import { Task, TaskService } from './../../core/core.module';

@Component({
  selector: 'app-task-dashboard',
  templateUrl: './task-dashboard.component.html',
  styleUrls: ['./task-dashboard.component.scss']
})
export class TaskDashboardComponent implements OnInit {
  tasks$;

  constructor(private taskService: TaskService) { }

  ngOnInit() {
    this.updateTaskList();
  }

  taskReceived(task){
    this.taskService.upsert(task).subscribe(r => {
      this.updateTaskList();
    });
  }

  updateTaskList(){
    this.tasks$ = this.getTasks();
  }

  deleteTask(task: Task) {
    this.tasks$ = this.taskService.remove(task).switchMap(_ => this.getTasks());
  }

  getTasks(){
    return this.taskService.getTasks().map(tasks => tasks.sort((a, b) => a.tag > b.tag ? +1 : -1));
  }
}

--- 
+++ 
@@ -1,4 +1,5 @@
-import { Component, OnInit } from '@angular/core';
+import { TaskListComponent } from './../task-list/task-list.component';
+import { Component, OnInit, ViewChild } from '@angular/core';
 import { Task, TaskService } from './../../core/core.module';
 
 @Component({
@@ -7,6 +8,8 @@
   styleUrls: ['./task-dashboard.component.scss']
 })
 export class TaskDashboardComponent implements OnInit {
+  @ViewChild(TaskListComponent) taskList: TaskListComponent;
+  
   tasks$;
 
   constructor(private taskService: TaskService) { }
Add task list reference to task dashboard.

