0

I have a function to render cards with information from my firebase DB.

The div that i'm using at javascript file:

                    <div class="col-md-4">
                      <div class="card mb-4 box-shadow">
                        <img class="card-img-top" data-src="${doc.data().foto}">
                        <div class="card-body">
                          <p class="card-text">Local: ${doc.data().local}</p>
                          <p class="card-text">Descricao: ${doc.data().descricao}</p>
                          <p class="card-text">Situacao: ${doc.data().situacao}</p>
                          <div class="d-flex justify-content-between align-items-center">
                            <div class="btn-group">
                              <button type="button" class="btn btn-sm btn-outline-secondary" data-toggle="modal" data-target="#myModal">Edit</button>
                              <button type="button" class="btn btn-sm btn-outline-secondary type="submit" onclick="deleteCard(${doc.id})">Apagar</button>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>

As you can see I need to create a button to delete this information.

I'm trying to pass to the function

function deleteCard(id) {


    db.collection("ocorrencias").doc(id).delete().then(function() {
        console.log("Document successfully deleted!");
    }).catch(function(error) {
        console.error("Error removing document: ", error);
    });

}


The console tho is sending the me the error:


Uncaught ReferenceError: IcKDt_____pUQcy is not defined
    at HTMLButtonElement.onclick (myindexLogged.html:1)

What i'm doing wrong ? 

2
  • Probably need to wrap deleteCard(${doc.id}) in quotes... deleteCard('${doc.id}') Commented Feb 4, 2021 at 22:57
  • i was trying " instead ' lol, thank you Commented Feb 5, 2021 at 14:46

1 Answer 1

1

Perhaps replace deleteCard(${doc.id}) with deleteCard(${doc.data().id})

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.