This code deletes the object on the server.

private deleteTask(taskId: number) { this.serv.deleteTask(taskId).subscribe(data => { if (data.status) { let index = this.tasks.indexOf(taskId); this.tasks.splice(index, 1); } }, error => console.log(error) ); } 

And I want to delete a line (element In DOM) by index in View. But the studio swears at indexOf(taskId) and writes:

Error TS2345 (TS) Argument of type 'number' is not assignable to parameter of type 'Task'

  let index = this.tasks.indexOf((taskId: number)); но не помогло. 

How to delete an item by index?

  • one
    Perhaps it is worth replacing both lines inside if by this.tasks = this.tasks.filter(task => task.id !== taskId) - diraria
  • So it turned out =) - Anton Evseev
  • Write the answer means) - diraria
  • And, if it's not a secret, what are you writing for the application?) - diraria
  • @diraria Already wrote. Test)) It remains to understand the date format ru.stackoverflow.com/questions/726944/… =) - Anton Evseev

1 answer 1

In this form it works

  if (data.status) { this.tasks = this.tasks.filter(task => task.id !== taskId); }