bradtraversy/angular-crash-todolist

deleting one new todo -> deletes all new todos

Opened this issue · 2 comments

Form submit doesn't generate todo.id, resulting in delete one new todo -> deletes all new todos. Can you please update the code?

Form submit doesn't generate todo.id, resulting in delete one new todo -> deletes all new todos. Can you please update the code?

The id property will always be 201. This is just a test API and so in the real world, the database would auto-increment the value of the id. The deleteTodo function in the todo.service.ts targets the id property only.

deleteTodo(todo: Todo): Observable {
const url = ${this.todosUrl}/${todo.id};
return this.http.delete(url, httpOptions);
}

https://jsonplaceholder.typicode.com/guide.html

This helps, thank you.