Login/logout issue


Im facing an issue regarding with the ionic login/lout development.
After login button click ,setting the userdetails in localstorage (localstorage.setItem()) and route to dashboard.
In dashboard im checking if data present in the localstorage or not, then display the login/logout button

But this isnt working properly, data set in the localstorage is fine.
but when i reach dashboard its still ‘login’ button
When i refresh the dashboard page this will change to ‘logout’ button

Same happening for logout (localstorage.clear()) function too

i am beginner can anyone help me out with this issue


First i suggest to get the localstorage value to an variable in the dashboard. then stringfy the value and check your conditions.

It seems to be a component scope problem, where is this button? Inside your dashboard page?

yes, inside the dashboard

hard to track, can you post your code?

How are you checking? Is it in your template? in ionViewWillEnter?

Use ngZone to run your method

import { NgZone } from '@angular/core';
constructor (private ngZone: NgZone) {

changeButton () {
     if (logged) {
        this.ngZone.run(() => {
            this.showLogoutButton = true;
            this.showLoginButton = false;
     } else {
            this.showLogoutButton = false;
            this.showLoginButton = true;