Hi,
I get the error: ERROR TypeError: “this.app is undefined” when I call the logout function.
I search around and I read something related the “undefined” errors but I don’t solve it.
I know that the getRootNav() is deprecated but still working.
Can you help me?
This my code:
import { Component } from '@angular/core';
import { NavController, App } from 'ionic-angular';
import { AuthService } from '../../providers/auth-service/auth-service';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
app: any;
public userDetails: any;
responseData: any;
userPostData = {"user_id":"","token":""};
constructor(public navCtrl: NavController, public authService:AuthService) {
const data = JSON.parse(localStorage.getItem('userData'));
this.userDetails = data.userData;
this.userPostData.user_id = this.userDetails.user_id;
this.userPostData.token = this.userDetails.token;
}
backToWelcome(){
const root = this.app.getRootNav();
root.popToRoot();
}
logout(){
//Remove API token
localStorage.clear();
setTimeout(() => this.backToWelcome(), 1000);
}
}