【发布时间】:2017-08-18 19:20:13
【问题描述】:
我有 5 个标签
<ion-tabs tabsPlacement="bottom" tabsLayout="icon-top" tabsHighlight="true" color="primary">
<ion-tab [root]="myCardsTabRoot" tabTitle="My Cards" tabIcon="ios-photos"></ion-tab>
<ion-tab [root]="calendarTabRoot" tabTitle="Calendar" tabIcon="calendar"></ion-tab>
<ion-tab [root]="myProfileTabRoot" tabTitle="My Profile" tabIcon="ios-person"></ion-tab>
<ion-tab [root]="searchTabRoot" tabTitle="Search" tabIcon="ios-search"></ion-tab>
<ion-tab [root]="pendingRequestsTabRoot" tabTitle="Follow Req" tabIcon="notifications" tabBadge="{{pendingRequests}}" tabBadgeStyle="danger"></ion-tab>
</ion-tabs>
我只想在有任何待处理请求时才显示最后一个选项卡,我在下面尝试了但仍然没有机会,并且当pendingRequests 值发生变化时不显示/隐藏选项卡,
pendingRequests 的值在 ionViewDidEnter() 中更改
<div *ngIf="pendingRequests > 0">
<ion-tab [root]="pendingRequestsTabRoot" tabTitle="Follow Req" tabIcon="notifications" tabBadge="{{pendingRequests}}" tabBadgeStyle="danger"></ion-tab>
</div>
和
<ion-tab *ngIf="pendingRequests > 0" [root]="pendingRequestsTabRoot" tabTitle="Follow Req" tabIcon="notifications" tabBadge="{{pendingRequests}}" tabBadgeStyle="danger"></ion-tab>
如果我重新启动应用程序,选项卡会根据 pendingRequests 的值正确显示,唯一的问题是当值更改时,选项卡不会相应地隐藏/显示
这里是更新pendingRequests的代码
ionViewDidEnter() {
this.refreshPrendingRequests();
}
refreshPrendingRequests() {
this.contactsService.getContactRequestsCount(this.userInfoService.currentProfile.id)
.subscribe(count => this.pendingRequests = count);
}
更新
根据@Sampath 的建议,我为它创建了一个 plunker。这种行为与我在我的应用程序上的行为不同,但这个行为也不起作用。
单击右上角的工具栏按钮应显示/隐藏选项卡 http://plnkr.co/edit/Cx6Pyr9AihvX66ASed0s?p=preview
【问题讨论】:
-
能否显示
pendingRequests代码sn-p的值变化? -
调试代码时能看到什么?价值变化是如何发挥作用的?
-
@Sampath 我在工具栏上添加了另一个按钮,该按钮隐藏和显示正确,因此这意味着更改值工作正常,甚至角度绑定工作正常
-
任何控制台错误或类似的错误?
-
@Sampath 感谢您的帮助
标签: ionic-framework ionic2 ionic2-tabs