Skip to content

Instantly share code, notes, and snippets.

@brachi-wernick
Last active January 14, 2018 13:03
Show Gist options
  • Save brachi-wernick/70fe2c5e0fc03151969bbd7bd10cc83f to your computer and use it in GitHub Desktop.
Save brachi-wernick/70fe2c5e0fc03151969bbd7bd10cc83f to your computer and use it in GitHub Desktop.
remove item with callback
private removeItem(item: Item) {
let index = this.items.indexOf(item);
//remove the item
this.items.splice(index, 1);
//call back-end server to remove the item from the DB
this.itemService.deleteItem(item.id).subscribe(
//do some stuff
,
error => {
//in case of error, add the callback to bring the item back and re-throw the error.
error.callback=()=>this.items.splice(index, 0, item);
throw error;
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment