I have a button that performs a logout on various views within my Tabs view container. The logout button runs the following code and works properly:
logout(){
this.app.getRootNav().setRoot(Login);
}
However when I log back into my application and then click the logout button, the function gets called but I does not set the root nav back to Login.
The login function sets the root to Tabs.
pixello
December 28, 2016, 7:44pm
2
Can you try this?
add viewchild and nav
import { ViewChild } from '@angular/core';
import { Nav } from 'ionic-angular';
define nav:
export class MyApp {
@ViewChild(Nav) nav: Nav;
instead of
this.app.getRootNav().setRoot(Login);
try to use this:
this.nav.setRoot(Login);
I get this error:
Error in ./Home class Home - caused by: Cannot read property 'setRoot' of undefined
pixello
December 28, 2016, 10:21pm
4
Your logout code are in your Home class?
I think you have to do this in your root class app.component.ts
How do I call that method from another class?
Here ’s how I deal with this concept.
I did that and it worked, but after setting root, logging back in again, and resetting the root after clicking the logout button it does not set the root back to the login page.