加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 离子3刷新侧面菜单登录后

发布时间:2020-12-17 07:57:37 所属栏目:安全 来源:网络整理
导读:我需要根据用户的角色显示侧面菜单项.所以我检查app.html是否页面(角色)等于登录角色.但是在登录后它不显示侧边菜单中的项目,但在使用浏览器refesh按钮刷新应用程序后,它会显示正确的项目. 我想问题是离子是缓存菜单视图,如果它是如此,我如何刷新应用程序以
我需要根据用户的角色显示侧面菜单项.所以我检查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);
  });
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读