Richard
Richard

Reputation: 8935

Ionic2: Property 'present' does not exist on type 'NavController'

I am using Ionic 2 rc4. I am following the advise here and am trying to do the following:

import { NavController } from 'ionic-angular';
        ...
    this.nav.present(this.loading).then(() => {

However, to me it looks like the NavController does not have a present function, because I get:

[ts] Property 'present' does not exist on type 'NavController'.
any

Am I correct, or am I doing something wrong? How do they get to access this "phantom" function?

Any advise appreciated.

UPDATE

Here is my code that results in the following error (on this.loading.present().then(() => {):

"Cannot read property 'nativeElement' of null"

It presents loading the first time. but after the alert is presented if submit() is run again, it gets this error.

submit() {
            this.loading.present().then(() => {
                let alert = this.alertCtrl.create({
                    title: 'Verify Email',
                    subTitle: 'Please verify your email address before you log in.',
                    message: 'Check your Spam folder if you cannot find the email.',
                    buttons: [
                        {
                            text: 'Resend',
                            handler: data => {
                                firebaseUser.sendEmailVerification().then((data) => {
                                    this.doAlert('Verify Email', 'Verification Email Sent.').then((data) => {
                                        //navCtrl.setRoot(navCtrl.getActive());
                                    });
                                });
                            }
                        },
                        {
                            text: 'Okay',
                            handler: data => {
                                //navCtrl.setRoot(navCtrl.getActive());
                            }
                        }
                    ]
                });
                alert.present();
                this.loading.dismiss();
            });
}

Upvotes: 1

Views: 4798

Answers (1)

Suraj Rao
Suraj Rao

Reputation: 29614

Looking at this changelog for Beta 11

They have removed present function from Navcontroller.

You need to refactor your code and use some other function based on your requirement. this.loading.present()

For the error, check the Loading controller docs.

Note that after the component is dismissed, it will not be usable anymore and another one must be created. This can be avoided by wrapping the creation and presentation of the component in a reusable function

Just do :

this.loading = this.loadingCtrl.create({
   //loading properties
          });

inside submit() before this.loading.present()

Upvotes: 4

Related Questions