我需要根据用户的角色显示侧面菜单项.所以我检查app.html是否页面(角色)等于登录角色.但是在登录后它不显示侧边菜单中的项目,但在使用浏览器refesh按钮刷新应用程序后,它会显示正确的项目.
我想问题是离子是缓存菜单视图,如果它是如此,我如何刷新应用程序以显示新的菜单项.
我想问题是离子是缓存菜单视图,如果它是如此,我如何刷新应用程序以显示新的菜单项.
每次我使用其他用户/角色登录时,它都会根据以前的用户/角色显示菜单.
app.component.ts
constructor() { this.initializeApp(); this.pages = [ { title: 'Home',component: 'HomePage',icon: 'home',role: 5 },{ title: 'Profile',component: 'ProfilePage',icon: 'person',{ title: 'Account',component: 'AccountPage',{ title: 'Search Employee',component: 'AtlasemployeehomePage',role: 4 } ]; }
app.html
<ion-list> <div *ngFor="let p of pages"> <button menuClose ion-item *ngIf="p.role == role" (click)="openPage(p)"> <ion-icon name="{{p.icon}}" style="margin-right:10%"></ion-icon> {{p.title}} </button> </div> <button menuClose ion-item (click)="presentLogout()"> <ion-icon name="log-out" style="margin-right:10%"></ion-icon> Logout </button> </ion-list>
我根据登录用户设置角色变量.
为此你可以使用
Events API
Events is a publish-subscribe style event system for sending and
responding to application-level events across your app.
import { Events } from 'ionic-angular'; // login.ts page (publish an event when a user is created) constructor(public events: Events) {} createUser(user) { console.log('User created!') this.events.publish('user:created',user,Date.now()); } // app.component.ts page (listen for the user created event after function is called) constructor(public events: Events) { events.subscribe('user:created',(user,time) => { // user and time are the same arguments passed in `events.publish(user,time)` console.log('Welcome','at',time); }); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。