【发布时间】:2019-10-09 20:31:49
【问题描述】:
我在 Ionic 3(Angular 和 Typescript)中使用平移和滑动手势来触发操作。现在我是这样使用它的:
*.html :
<button ion-button block (panleft)="actionForLeftPan()" (panright)="actionForRightPan()">Touch me</button>
*.ts:
actionForLeftPan(): void
{
// Some actions
}
actionForRightPan(): void
{
// Some other actions
}
它可以工作,但在某些情况下,它需要在 html 文件中调用很多函数。有没有办法做一些事情,例如这样的事情:
*.html:
<button ion-button block (pan)="actionForPan(event)">Touch me</button>
*.ts:
actionForPan(event): void
{
if ( event.left )
{
// Do some actions
}
if ( event.right )
{
// Do other actions
}
}
这将大大简化代码的可读性和维护。
【问题讨论】:
-
你所要做的就是在调用 (pan)="actionForPan($event)" 时传入 $event。您应该在 actionForPan() 中使用 console.log(event) 来查看结果。
-
谢谢JoeriShoeby,这正是我所需要的。
标签: angular ionic-framework ionic3