按下按钮时 Ionic2 关闭 fab 菜单
Ionic2 close fab menu when button pressed
如何在按下菜单中的按钮时关闭打开的 FAB 菜单?
这是我的按钮。
<ion-fab bottom center >
<button ion-fab><b>Hello</b></button>
<ion-fab-list side="top">
<button ion-fab (click)="refresh()"><ion-icon name="refresh"></ion-icon></button>
我必须向 refresh
添加什么才能关闭整个 FAB?
我能以某种方式从代码中引用 html 对象吗?类似于 iOS 处理其出口的方式?
只需将 #fab
添加到 ion-fab
标签:
<ion-fab bottom center #fab>
<button ion-fab (click)="refresh(fab)">
<ion-icon name="refresh"></ion-icon>
</button>
</ion-fab>
并使用 FabContainer
方法 close()
在您的 FAB 按钮调用的任何函数开始时关闭 FAB 菜单(如果打开),例如:
import { FabContainer } from 'ionic-angular';
// remember to pass the fab from client side
refresh(fab?: FabContainer): void {
if (fab !== undefined) {
fab.close();
}
(other function stuff...)
}
关闭 html 文件中没有 .ts 函数的 FAB;您可以在 html 标签中使用 fab.close()
:
<ion-fab bottom left #fab>
<ion-fab-list side="top">
<button [navPush]="cart" (click)="fab.close()" *ngIf="loggedIn" ion-fab>
</ion-fab-list>
</ion-fab>
它是如此简单,而且您可以为单个事件使用多个函数(例如 (click)
事件):
<button *ngIf="loggedIn" (click)="logout()" (click)="fab.close()" ion-fab>
请勿在标签中伪造位置 #fab
:<ion-fab #fab>
对于仅使用此解决方案的新版本(我知道,我知道,超时...):
TS:
@ViewChild('fab') _fab: IonFab;
public closeFab(){
let t = setTimeout(() => {
this._fabRight.close();
}, 100);
}
HTML:
<ion-fab vertical="bottom" horizontal="end" #fab>
<ion-fab-button color="secondary">
<ion-icon name="eye"></ion-icon>
</ion-fab-button>
<ion-fab-list side="start">
<ion-fab-button (click)="closeFab()">
<ion-icon name="add"></ion-icon>
</ion-fab-button>
</ion-fab-list>
</ion-fab>
如何在按下菜单中的按钮时关闭打开的 FAB 菜单?
这是我的按钮。
<ion-fab bottom center >
<button ion-fab><b>Hello</b></button>
<ion-fab-list side="top">
<button ion-fab (click)="refresh()"><ion-icon name="refresh"></ion-icon></button>
我必须向 refresh
添加什么才能关闭整个 FAB?
我能以某种方式从代码中引用 html 对象吗?类似于 iOS 处理其出口的方式?
只需将 #fab
添加到 ion-fab
标签:
<ion-fab bottom center #fab>
<button ion-fab (click)="refresh(fab)">
<ion-icon name="refresh"></ion-icon>
</button>
</ion-fab>
并使用 FabContainer
方法 close()
在您的 FAB 按钮调用的任何函数开始时关闭 FAB 菜单(如果打开),例如:
import { FabContainer } from 'ionic-angular';
// remember to pass the fab from client side
refresh(fab?: FabContainer): void {
if (fab !== undefined) {
fab.close();
}
(other function stuff...)
}
关闭 html 文件中没有 .ts 函数的 FAB;您可以在 html 标签中使用 fab.close()
:
<ion-fab bottom left #fab>
<ion-fab-list side="top">
<button [navPush]="cart" (click)="fab.close()" *ngIf="loggedIn" ion-fab>
</ion-fab-list>
</ion-fab>
它是如此简单,而且您可以为单个事件使用多个函数(例如 (click)
事件):
<button *ngIf="loggedIn" (click)="logout()" (click)="fab.close()" ion-fab>
请勿在标签中伪造位置 #fab
:<ion-fab #fab>
对于仅使用此解决方案的新版本(我知道,我知道,超时...):
TS:
@ViewChild('fab') _fab: IonFab;
public closeFab(){
let t = setTimeout(() => {
this._fabRight.close();
}, 100);
}
HTML:
<ion-fab vertical="bottom" horizontal="end" #fab>
<ion-fab-button color="secondary">
<ion-icon name="eye"></ion-icon>
</ion-fab-button>
<ion-fab-list side="start">
<ion-fab-button (click)="closeFab()">
<ion-icon name="add"></ion-icon>
</ion-fab-button>
</ion-fab-list>
</ion-fab>