derrida
asked on
firebase storage angularfire and angular 2: problem with scope?
hi
i am using firebase database to store data and firebase storage to store images. i have a libraries node and an image associated with that library.
i want to delete a library and it's associated image. i manage to do both but not in a logical manner because i get undefined.
this is my code:
this.libraries.remove(id); this line, which delete the library from the database, doesn't work within the promise, where it should be logical. i get the error that this.libraries is undefined. but if i use the same code at the end, it does recognize this.libraries. so i can delete it at the end, i just don't understand why within the scope of the promise, i can't use it.
what am i missing?
best regards
i am using firebase database to store data and firebase storage to store images. i have a libraries node and an image associated with that library.
i want to delete a library and it's associated image. i manage to do both but not in a logical manner because i get undefined.
this is my code:
deleteLib(id: string){
//console.log(id);
let thisLibImagePath = this.libService.getLibImagePlace(id);
var libsStorageRef = firebase.storage().ref('images/libs/');
// Create a reference to the image we need to delete
var LimageRef = libsStorageRef.child(thisLibImagePath);
// Delete the file
LimageRef.delete().then(function() {
console.log("deleted successfully");
this.libraries.remove(id);
}).catch(function(error) {
console.log(error);
});
//this.libraries.remove(id);
}
this.libraries.remove(id);
what am i missing?
best regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.