Subscribe is called twice

I’m trying to create a form to submit the details but when I subscribe the service, the subscription is done twice. First with null data and second with actual data.


addBook() {
    this.errorMessage = null;
    this.fireService.getBook(this.bookDetails.isbn).subscribe(data => {
      console.log('subscribe called');
      if (null != data) {, {
          data: { title: 'Error', content: 'Book is already present in Library. Select Edit book to modify the details', button: false }
        this.errorMessage = 'Book is already present in Library. Select Edit book to modify the details';
      } else {
        this.fireService.addBook(this.bookDetails);, {
          data: { title: 'Success', content: 'Book has been Added to Database', button: false }


getBook(id) {
  console.log('called firebase get book');
  return this.db.doc(`/books/${id}`).valueChanges();

Below is the image from the console of chrome. This shows that the subscription is called twice but not the firebase service.

Chrome console logs: Image please click to view

chrome console logs

called firebase get book
subscribe called
subscribe called

Please help

85 thoughts on “Subscribe is called twice”

  1. 659890 665680Lastly, got what I was looking for!! Ive actually enjoying every small bit of this. Ecstatic I stumbled into this post! and also Ive bookmarked to look at exclusive data for your blog post. 842545


Leave a Comment