Error: Reference.child failed: First argument was an invalid path

后端 未结 2 702
南笙
南笙 2021-01-24 23:45

I have this small app with Firebase and i\'m implementing CRUD operations. The issue comes when I have to delete a post. I get this error: Error: Reference.child failed: F

相关标签:
2条回答
  • 2021-01-25 00:22

    @Frank van Puffelen snapshotChances() was the solution. This methods returns the id from the node to delete in firebase. So, in the service, I get the reviews like this:

    getReviews() {
        return this.db.list('/reviews').snapshotChanges();
      }
    

    And the HTML should be

     <button (click)="delete(r.key)" class="btn btn-danger">Delete</button>
    

    And back in the service, the delete method:

    deleteReview(id: any) {
        console.log(id)
        this.db.object('reviews/' + id).remove();
      }
    
    0 讨论(0)
  • 2021-01-25 00:39

    You seem to be changing the meaning of p from post to an id. Assuming that each post has an id property, you probably want:

    delete(post) {
      this.postService.deletePost(post.id)
    }
    
    0 讨论(0)
提交回复
热议问题