Last active
January 14, 2018 13:03
-
-
Save brachi-wernick/70fe2c5e0fc03151969bbd7bd10cc83f to your computer and use it in GitHub Desktop.
remove item with callback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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