DEV Community

Mateusz Tomczyk
Mateusz Tomczyk

Posted on

Angular- Delete item from array of object

Here's my app: https://stackblitz.com/edit/angular-ivy-s6usrl?file=src%2Fapp%2Fnotes%2Fsingle-note%2Fsingle-note.component.ts

As you can see I try to delete item but it doesn't work, can sb look at that? Thanks alot!

Top comments (5)

Collapse
 
alexf profile image
Alex F.

You need Two-way-binding between components:
stackoverflow.com/a/36247095
Changes Template
Changes Component

Although I would probably create a service and put the array and all the methods (for create, delete, update etc) there and in the component just use that service.

Collapse
 
mateuszto profile image
Mateusz Tomczyk

Did you know now how to solve problem with id when i delete all notes and try to add a new one?

Collapse
 
alexf profile image
Alex F. • Edited

This works:
new set

Although I'm no expert XD. Seems logical you can't reverse an empty array.

Thread Thread
 
mateuszto profile image
Mateusz Tomczyk

Thank you so much!

Collapse
 
mateuszto profile image
Mateusz Tomczyk

Thanks a lot!