Unable to navigate in succes callback of rest call

#1

Hi there,

I am fairly new to ionic and seem to be stuck with a basic issue.

I have a rest call which comes back successfully. The console logs in this succes callback execute without problems. But i want to navigate to another page. For this i use this.navCtrl.push(PhotoOverviewPage);

The funny parts is when i comment the rest call and just execute the navctrl function it works fine. But within a success callback it does nothing. I don’t get any errors or warnings.

Does work

doLogin(){
      this.navCtrl.push(PhotoOverviewPage);
}

Does not work

doLogin(){
   this.loginService.doLogin(this.url, this.username, this.password).then(function(data: any){
      console.log("Login came back with data: ");
      console.log(data);
      this.navCtrl.push(PhotoOverviewPage);
   });
}

Maybe i am just missing something.
Thanks in advance,
Robin

#2

Never type the word “function” inside the body of one. Use an arrow function instead. You are losing execution context.