Read Storage Value from Constructor Gives error


#1

When i read value from constructor third time give error.

Uncaught (in promise): TypeError: Cannot read property ‘name’ of null TypeError: Cannot read property ‘name’ of null at

Following is my code.

constructor(public navCtrl: NavController, public navParams: NavParams,
    public loadingCtrl: LoadingController,
    private serviceListService: ServiceListService,
    public storage: Storage,
    public modalCtrl: ModalController
) {

     // Get UserId Value From Storage
    storage.get('UserId').then((val) => {
        alert(val);
        if (val != null && val != "") {
            let modal = this.modalCtrl.create(ModalChangeCityPage);
            modal.present();
        } else {
            let modal = this.modalCtrl.create(ModalRegisterUserPage);
            modal.present();
        }
    })
}

#2

The error message is complaining about an attempt to read the property ‘name’ of an undefined entity. You have not shown any code referencing a ‘name’ property.


#3

Hey,

Thanks for your response. One thing i don’t understand is its give error third time. When i come to this page two time it work perfectly, If UserId is not available open ModalRegisterPage or ChangeCityPage.

Why it give error on third time…?


#4

You probably have a race condition, but again it’s impossible for anybody to magically divine what your code looks like.