【发布时间】:2020-02-12 22:50:04
【问题描述】:
谁能给我一个工作示例,说明如何使用 angular 在离子中使用切换承诺。
toggle(animated?: boolean) => Promise<boolean>
我想在菜单关闭时调用用户定义函数。如何使用上面的切换。我有 seen this 但这不能回答我的问题
【问题讨论】:
标签: angular typescript ionic-framework
谁能给我一个工作示例,说明如何使用 angular 在离子中使用切换承诺。
toggle(animated?: boolean) => Promise<boolean>
我想在菜单关闭时调用用户定义函数。如何使用上面的切换。我有 seen this 但这不能回答我的问题
【问题讨论】:
标签: angular typescript ionic-framework
如果该方法返回一个带有布尔值的 Promise,则需要在此类 Promise 解决后调用自己的方法:
import { Component } from '@angular/core';
import { MenuController } from '@ionic/angular';
@Component({
selector: 'menu-example',
templateUrl: 'menu-example.html',
styleUrls: ['./menu-example.css'],
})
export class MenuExample {
constructor(private menu: MenuController) { }
myCustomMethod() {
// your custom method logic
}
openCustom() {
this.menu.toggle(true).then((toggled) => {
if (toggled) {
this.myCustomMethod()
}
})
}
}
【讨论】:
在您的 app.html 文件中
<ion-menu side="start" menuId="first" contentId="main" (ionDidClose)="menuClosed()">
然后在 app.ts 文件中编写事件处理函数
menuClosed() {
//code to execute when menu has closed
}
PS:关闭菜单时会发出 ionDidClose。
【讨论】: