Logout Button Does Not Work After Logging Back In

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:


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.

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


try to use this:


I get this error:

Error in ./Home class Home - caused by: Cannot read property 'setRoot' of undefined

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.