Angular 4 allows for the deletion of specific row data from Firebase

I'm currently working on an Angular 4 project and I need to be able to delete a row from Firebase when it's clicked.

Here is the code for my smart table:

<ng2-smart-table [settings]="settings" [source]="source" (edit)="onEdit($event)" (delete)="onDelete($event)">
    </ng2-smart-table>

The onDelete() function looks like this:

onDelete(event) {
console.log(event);
if (window.confirm('Are you sure you want to delete?')) {
this.service.deleteEnquiry(event.data);
} else {
event.confirm.reject();
}
}

I've implemented the deleteEnquiry function in the service as shown below:

deleteEnquiry(data){
console.log(data);
this.af.list('/enquirydata/').remove(data);
}

However, I'm encountering an issue where it's not working and displaying the following error in the console:

ERROR Error: Expects a string, snapshot, or reference.

Can anyone offer some assistance?

Answer №1

give this a shot

removeInquiry(info){
    console.log(info.$id);
    this.db.list(`/inquiry/${info.$id}`).delete(info);
 }

Answer №2

Make sure to pass the event.value when calling the service function in your onDelete method.

 onDelete(event) {
  console.log(event.value);
  if (window.confirm('Are you sure you want to delete?')) {
    this.service.deleteEnquiry(event.value);
  } else {
    event.confirm.reject();
  }
 }

Update your service code as follows:

 deleteEnquiry(data){
    console.log(data.$key);
    this.af.list(`/enquirydata/${data.$key}`).remove(data);
  }

Answer №3

Make sure to also take a look at this document: https://github.com/angular/angularfire2/blob/master/docs/rtdb/lists.md

The Function of snapshotChanges() What does it do? - It provides an Observable containing data in the form of a synchronized array of AngularFireAction[].

Why would you use this feature? - If you require a list of data while retaining associated metadata. The metadata includes the underlying DatabaseReference and snapshot key, which can be beneficial for data manipulation tasks. This function enhances compatibility with other Angular features like ngrx, forms, and animations thanks to its type property. The type property within each AngularFireAction is particularly valuable for ngrx reducers, form states, and animation states.

When should you avoid using it? - If you need a more intricate data structure than an array or if real-time processing of changes is necessary. This array remains synchronized with both remote and local modifications on the Firebase Database.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve the code from the Firebase console that was previously deployed

I recently set up Firebase functions using Node.js and deployed the code on Firebase. One of the functions was designed to send an email whenever a new user is created. Unfortunately, I seem to have misplaced the code. Is there any way we can retrieve th ...

Leveraging Array.map within Angular Interpolation

Is it possible to achieve the following in HTML using Angular 2+? {{ object.array.map((o) => o.property ) }} Whenever I try to execute this code, it crashes the Angular application. Do I need to utilize Pipes or any other technique? ...

When converting a PDF to a PNG, the precious data often disappears in the process

I am currently facing a problem with the conversion of PDF to PNG images for my application. I am utilizing the pdfjs-dist library and NodeCanvasFactory functionality, but encountering data loss post-conversion. class NodeCanvasFactory { create(w, h) { ...

Issue with Angular not functioning properly in IE 11 across both production and development builds

After updating my global angular-cli version to 8, I encountered an error in IE11 when building my project in production mode. Interestingly, the project works fine in Chrome. The error message for the production version is as follows: https://i.sstatic. ...

Setting up WebPack for TypeScript with import functionality

A tutorial on webpack configuration for typescript typically demonstrates the following: const path = require('path'); module.exports = { ... } Is it more advantageous to utilize ES modules and configure it with import statements instead? Or is ...

Tips for effectively updating multiple selection options from a component

I am currently in the process of making updates to a multi-select from the component. Instead of using an array property as the model for the select, I opted for an object property. When an option is selected, the object property is updated accordingly. ...

How can I center align my loader inside app-root in Angular2+?

I've successfully added a basic spinner to my <app-root> in the index.html file. This gives the appearance that something is happening behind the scenes while waiting for my app to fully load, rather than showing a blank white page. However, I& ...

Using Material UI with React and TypeScript

I need some assistance with organizing my menus correctly in React using TypeScript. Currently, they are displaying on top of each other instead of within their respective category menus. I have been struggling to find a solution and would appreciate any h ...

mongodb is experiencing issues with the findOneAndUpdate operation

Below is the code snippet for updating the database. let profileUrl = 'example' UserSchemaModel.findOneAndUpdate({_id:userId}, {$set: {profileUrl:profileUrl} }, {new:true}) .then((updatedUser:UserModel) => { console.log(updatedUser.profil ...

What is the best way to send a variable to an arrow function?

Is there a way to use the selector parameter inside an arrow function for an if statement without receiving an error stating that the selector is not defined? static async valuesToArray(selector: string): Promise<void> { const data: (string | D ...

NodeJS code encountered an issue while attempting to send a cloud notification

Currently exploring nodeJs as a novice, attempting to establish a connection with a cloud server for sending notifications via Firebase Cloud Messaging. // Incorporating the Cloud Functions for Firebase SDK to create functions and set up triggers. cons ...

Using Angular template to embed Animate CC Canvas Export

Looking to incorporate a small animation created in animate cc into an angular template on a canvas as shown below: <div id="animation_container" style="background-color:rgba(255, 255, 255, 1.00); width:1014px; height:650px"> <canvas id="canv ...

Choose a Superclass or Interface for your Subclass

I currently have the following setup: class Dog extends Animal{} class Animal{} This is a simple inheritance structure. Now, I have another class that contains all types of animals. class Farm{ animals: Animal[]; } At a certain point in my applic ...

Sequelize's bulk synchronization process is ineffective

I am facing an issue with getting sequelize.sync() to function properly. When I call sync() for each model definition individually, it works perfectly fine. However, when trying to execute it from the sequelize instance itself, it seems like the registered ...

I encountered an issue while trying to implement a custom pipe using the built-in pipe

My custom pipe seems to be functioning well, except for the built-in pipes not working within it. I've imported Pipe and can't figure out what could be causing the issue. Below is the code with the errors: import { Pipe, PipeTransform } from &a ...

Detecting parent changes in Angular 2 child components

Currently, I am facing an issue with a component that displays a list of 'items' which are components created using a selector. I have a checkbox that I want to update the 'state' of all child components when clicked. Struggling to fin ...

Flashing Screens with Ionic 2

I am currently dealing with a situation where my login page and homepage are involved. I have implemented native storage to set an item that helps in checking if the user is already logged in (either through Facebook or Google authentication). The logic fo ...

unable to locate package "@angular/material"

Having an issue with Angular 2 as I try to import "@angular/material". The error occurs when importing packages like: import {MdDialog} from "@angular/material"; import {MdDialogRef} from "@angular/material"; Here is my tsconfig.json file: { "compilerO ...

Using Vue with Typescript to leverage generics for interfaces

What is the proper syntax for allowing any type that extends a base type in this specific scenario? interface SomeBase {} interface A extends SomeBase {} interface B extends SomeBase {} interface Foo { bar: // Can be an array of A or B } Is it simply ba ...

Unable to utilize AgmMarkerSpiderModule

I followed the instructions to add the AgmMarkerSpiderModule from the official package documentation. However, when I compile, I encountered the following error message: /directives/marker-spider.ts:14:24 - error TS2307: Cannot find module '@agm/core/ ...