Ionic creates multiple views when using AngularFire CRUD


#1

I am performing crud operations on firebase db. In particular the add and update operation seem to create new views of current page and not respecting navcontroller.pop()
As soon as I click Save the address is saved or updated based on operation but then new view of same page gets created. The constructor of address page and ionViewDidEnter method gets executed again. This is very weird behaior.

In Address page when I update the address using Firebase the new view of AddressPage is created.
Has anyone come across this behavior?

I am using ionic-angular 3.9.0 and AngularFire 5.0

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

 //navigate to different view
 navigate(){
    self.navCtrl.push(AddressPage, {address:newAddress});
 }

}

@Component({
  selector: 'page-address',
  templateUrl: 'address.html'
})
export class AddressPage {

   ionViewDidEnter(){
      //load some data from server
   }

   saveAddress(){
    if(this.addressKey){
       this.firebaseProvider.updateAddress(this.addressKey, updateItems);
        loadingSpinner.dismiss();
        this.navCtrl.pop()
     }else{
       this.firebaseProvider.saveAddress(newAddress).then(result => {
         // loadingSpinner.dismiss();
         this.navCtrl.pop();
       });
     }
   }

}

The firebase provider class that performs all the db oprations

import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';

@Injectable()
export class FirebaseProvider {

  constructor(public afd: AngularFireDatabase) { }

  //pushes the address and returns unique key
  addAddress(address) {
    return this.afd.list('addresses').push(address).key;
  }


  updateAddress(key,dataToUpdate){
    this.afd.list('addresses').update(key,dataToUpdate);
  }

}


#2

Type your functions. If you do, the compiler will help you catch these problems. For example, updateAddress is currently void, but you’re treating it like a Promise.


#3

@AaronSterling Yep I am aware of that I have updated the code


#4

I don’t see any difference. The error I described is still there.