Chetan Nandanwar Chetan Nandanwar - 15 days ago 10
HTTP Question

How to re-render my table on each http delete in angular 2?

I am trying to delete rows from the table which is getting populated with data from rest APIs. Delete operation works fine except at last row. Whenever I try to delete the last row, it gets removed but doesn't disappear from the table. While on deleting the last row my get API gives 404 data not found error as last entry gets removed. So how can I handle 404 error and re- render my table such that it shows zero rows?

Answer

Can you give a proper explanation of your question? According to my understanding, there is two way to implement: First, while making delete API call, get again whole array(table) object which is not a good idea. So better idea is, while making delete API call based on Id(s) if you are getting successful response, then remove that/those row(s) based on row(s) id and if you get error then show to user with specific error message.

deleteRow() {
    this._testService.deleteRow(this.selectedRow)
      .subscribe(
        response => {
            this.rowsData.splice(this.selectedRowIndex, 1);
        },
        error => {
            this.errorMessage = < any > error;
        }
    );
}

Now point is: why last row deleting is getting error? you have to figure it out in backend OR check if you are calling API properly or not.

Hope will help you otherwise give little more explanation on the same.