0

Hello I am struggling to redirect the landing page after successful login to ionic3 apps. It always shows error: ERROR TypeError: "this.navCtrl is undefined" doLogin(){ $.ajax({ type: 'get', url: 'http://my_server_ip_address/php/login.php?u='+this.UserInfoForm.username+'&p='+this.UserInfoForm.password, success: function (res) { window.localStorage['userInfo'] = JSON.stringify(res); this.navCtrl.setRoot('clientDashboard'); }, error:function(){ this.navCtrl.setRoot('LoginPage');
} });
}

my constructor:

constructor(public navCtrl: NavController,
    public navParams: NavParams,
    private formBuilder: FormBuilder,
    private menu: MenuController) {
    this.menu.enable(true); // Enable sidemenu
}
sebaferreras
  • 44,206
  • 11
  • 116
  • 134
Enayet Hossain
  • 187
  • 1
  • 4
  • 14
  • 1
    Possible duplicate of [Cannot read property 'navCtrl' of undefined](https://stackoverflow.com/questions/43418146/cannot-read-property-navctrl-of-undefined) – sebaferreras Sep 01 '18 at 08:02
  • Possible duplicate of [How to access the correct \`this\` inside a callback?](https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback) – Gabriel Barreto Sep 03 '18 at 19:46
  • The problem is the way you're using the `this` inside a callback, your passing a callback with `function` decorator and you need an `arrow function`. – Gabriel Barreto Sep 03 '18 at 19:47
  • thanks bro.. the arrow function solved my problem – Enayet Hossain Sep 05 '18 at 04:01

0 Answers0