I have successfully implemented ng-bootstrap table complete example.
Object deletion from DOM and database are working, but I can't find a way to delete row from view. In order to see the changes page reload is required. Please notice, that delete function is and should be triggered, from ng-bootstrap modal dialog confirm button.
I can't call data$
from the for
loop like in the bellow approach or similar ones, because todo
(or what ever) is observable todos$
,
<!-- html -->
<tr *ngFor="let todo of tableService.todos$ | async;">
// typescript
deleteRow(id){
for(let i = 0; i < this.data.length; ++i){
if (this.data[i].id === id) {
this.data.splice(i,1);
}
}
}
Could someone point me to the right direction, please.
I have this chunk of code:
deleteTodo(id: string) {
this.todoService.deleteTodo(id)
.subscribe(data => {
console.log(data); // print message from server
},
error => console.log(error)
);
this.tableService.todoArray = this.tableService.todoArray.filter(elem => elem._id !== id);
this.todoLength--;
this.modalService.dismissAll();
console.log('filtered array: ' + this.tableService.todoArray.length);
console.log('id: ' + id);
}
This function deletes todo item from database and filter method deletes todo from an array. Please look at the screenshot bellow.
repo to my app source code:
https://github.com/SrdjanMilic/NG-Bootstrap-Todo-list