2016-10-05 48 views
0

問題發生一次註銷按鈕被按下時,或當我添加以下代碼:頁停留在logoout

this.local = new Storage(); 
    this.local.get('token').then((value)=>{ 
     this.token=value; 
}); 

頁被卡住和Chrome瀏覽器需要重新啓動。我想要做的就是當按下注銷來移除該標記時從存儲中獲取標記變量。

頁:

import { Component, ViewChild } from '@angular/core'; 
import { Nav, Platform } from 'ionic-angular'; 
import { StatusBar } from 'ionic-native'; 
import { Storage } from '@ionic/storage'; 
import { Page2 } from '../pages/page2/page2'; 
import {Admin} from "../pages/admin/admin"; 
import {Page1} from "../pages/page1/page1"; 

@Component({ 
    templateUrl: 'app.html', 
}) 

export class MyApp { 
    @ViewChild(Nav) nav: Nav; 
    rootPage: any = Page1; 
    token:any; 
    pages: Array<{title: string, component: any}>; 
    public local : Storage; 

    constructor(public platform: Platform,public storage:Storage) { 
     this.initializeApp(); 
     this.local = new Storage(); 
     this.local.get('token').then((value)=>{ 
      this.token=value; 
     }); 
     // used for an example of ngFor and navigation 
     this.pages = [ 
      { title: 'Page one', component: Page1 }, 
      { title: 'Page Two', component: Page2 }, 
      { title: 'Admin', component: Admin } 
     ]; 
    } 

    initializeApp() { 
     this.platform.ready().then(() => { 
      // Okay, so the platform is ready and our plugins are available. 
      // Here you can do any higher level native things you might need. 
      StatusBar.styleDefault(); 
     }); 
    } 

    openPage(page) { 
     // Reset the content nav to have just this page 
     // we wouldn't want the back button to show in this scenario 
     this.nav.setRoot(page.component); 
    } 

    Logout() { 
     console.log("logout check"); 
     this.local.remove('username'); 
     this.local.remove('token'); 
     this.nav.setRoot(Page1); 
     this.token=""; 
    } 
} 

回答

0

我找到了解決方案,它不再停留.. 我刪除了所有本地(儲存變量),那麼我定義的存儲:在我的構造函數的存儲和I使用它作爲離子2將日誌解釋爲storage.get(key)。