0

src/app/views/tasks/tasks.component.ts:12:3 - error TS2564: Property 'tasks' has no initializer and is not definitely assigned in the constructor. 12 tasks: Task[];

export class TasksComponent implements OnInit {

  tasks: Task[];

  constructor(private dataHandler: DataHandlerService) {

  }

  ngOnInit() {
    this.dataHandler.tasksSubject.subscribe(tasks=>this.tasks = tasks);
  }
}

1 Answers1

0

The compiler is repporting the error because tasks is not init and will only get a value once the subject has submitted a value.

you probably should have :

export class TasksComponent implements OnInit {
   tasks: Task[]|undefined;
}

To represent that tasks are undefined until the subscription.

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134