I am on project project management in the Angular course.
I am stumped on this.
In my ProductService I can remove an object from the Realtime database as long as I call it from the constructor, but if I call remove from my delete function (see below) the object does not delete from the database. Anyone ever run into this?
export class ProductService {
itemsRef: AngularFireList<any>;
items: Observable<any[]>;
// this works from the constructor
constructor(private db: AngularFireDatabase) {
this.itemsRef = db.list(â/productsâ);
// Use snapshotChanges().map() to store the key
this.items = this.itemsRef.snapshotChanges().pipe(
map(changes =>
changes.map(c => ({ key: c.payload.key, âŚc.payload.val() }))
)
);
db.object(â/products/-MQ-WK-e1GUtxLPhGBfMâ).remove()
}
/* does not work */
delete(productId) {
console.log(âproducts/â + productId);
this.db.object(â/products/-MQ-WK-e1GUtxLPhGBfMâ).remove()
.catch(error => console.log(error));
}