【发布时间】:2020-09-22 23:13:14
【问题描述】:
我想根据 ionic 中的条件禁用侧边菜单中的按钮。需要检查的条件只有在我登录应用程序后才可用。我正在像这样在 app.component.ts 中定义我的页面
// used for an example of ngFor and navigation
this.pages = [
{
title: "menu",
component: MenuPage,
src: "assets/imgs/grid.png",
color:
this.localStorage.getItem("highlight") == "menu" ? "danger" : "light",
class:
this.localStorage.getItem("highlight") == "menu"
? "item-md-danger"
: "",
isEnabled: true,
},
{
title: "about app",
component: AboutPage,
src: "assets/imgs/smartphone.png",
color:
this.localStorage.getItem("highlight") == "about app"
? "danger"
: "light",
class:
this.localStorage.getItem("highlight") == "menu"
? "item-md-danger"
: "",
isEnabled: true,
},
.
.
.
{
title: "Renew Subscription",
component: PlansPage,
src: "assets/imgs/subscription.png",
color: "light",
isEnabled:
this.localStorage.getItem("plantoptitle") == "Subscription expired"
? true
: false,
},
{
title: "Logout",
component: LoginPage,
src: "assets/imgs/logout_m.png",
color: "light",
isEnabled: true,
},
];
}
在这里您可以看到续订页面,我在那里使用了一个条件来启用和稳定该选项,我只有在从 API 响应登录后才能获得该选项。这是我的 app.html 页面
<ion-menu
[content]="content"
side="right"
persistent="true"
(ionOpen)="openMenu()"
>
<ion-header>
<ion-toolbar>
<ion-title>
<div class="menutp"><img src="assets/imgs/header_tp.png" /></div>
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<button
id="{{p.title}}"
menuClose
ion-item
*ngFor="let p of pages"
color="{{p.color}}"
(click)="openPage(p)"
[disabled]="!p.isEnabled"
>
<span><img src="{{p.src}}" class="imgH" /></span>
<span>{{p.title}}</span>
</button>
</ion-list>
</ion-content>
</ion-menu>
<!-- Disable swipe-to-go-back because it's poor UX to combine STGB with side menus -->
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
但是这种情况不能正常工作。如果我的订阅已过期并且当我第一次尝试登录时,进入菜单页面并打开侧面菜单以检查续订选项,它仍然被禁用。但是,假设我在登录后现在在菜单页面中,当我尝试再次运行构建并在成功构建并尝试打开侧面菜单时,现在它已启用,或者如果我在登录后滑动关闭应用程序并且重新打开它,按钮已启用。我该如何解决这个问题?我认为 isEnabled 条件检查没有正确调用,我希望根据订阅过期状态启用/禁用它。
【问题讨论】:
标签: html angular ionic-framework ionic3 angular5