【发布时间】:2017-03-31 16:31:34
【问题描述】:
ionic start mySideMenu sidemenu --v2
使用这个我创建了一个侧边菜单,我正在做一些登录-注销的事情,所以我将用户详细信息存储在名为“userDetails”的本地存储变量中。当我从侧面菜单单击注销选项时,它被重定向到登录页面。
import { homePage } from '../pages/home/home';
import { DetailsPage } from '../pages/Details/Details';
import { AddclientPage } from '../pages/Addclient/Addclient';
import { Storage } from '@ionic/storage';
import { LoginPage } from '../pages/login/login';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = homePage;
pages: Array<{title: string, component: any,icon:string}>;
constructor(platform: Platform,public storage:Storage,public mqttservice:Mqttservice) {
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();
Splashscreen.hide();
});
this.pages = [
{ title: 'Home ', component: homePage ,icon:"home"},
{ title:'Addclient',component:AddclientPage,icon:'add'},
{title: 'Users' ,component:DetailsPage,icon:"people"},
{ title:'addclient',component:AddclientPage,icon:"person-add"},
{title:'Logout',component:LoginPage,icon:"log-out"}
];
}
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);
}
}
但我想要的是当用户单击注销时,删除本地存储变量,然后重定向到登录页面 所以我写了一个删除“userDetails”并重定向到“loginpage”的方法,但出现“无法读取未定义的属性'setRoot'”之类的错误
import { homePage } from '../pages/home/home';
import { DetailsPage } from '../pages/Details/Details';
import { AddclientPage } from '../pages/Addclient/Addclient';
import { Storage } from '@ionic/storage';
import { LoginPage } from '../pages/login/login';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = homePage;
pages: Array<{title: string, component: any,icon:string}>;
constructor(platform: Platform,public storage:Storage,public mqttservice:Mqttservice) {
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();
Splashscreen.hide();
});
this.pages = [
{ title: 'Home ', component: homePage ,icon:"home"},
{ title:'Addclient',component:AddclientPage,icon:'add'},
{title: 'Users' ,component:DetailsPage,icon:"people"},
{ title:'addclient',component:AddclientPage,icon:"person-add"},
{title:'Logout',component:this.logout(),icon:"log-out"}
];
}
logout(){
this.storage.remove('userDetails);
this.nav.setRoot(LoginPage);
}
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);
}
}
【问题讨论】:
标签: angular typescript ionic-framework ionic2