我试图在元素上添加自定义longPress事件指令,因为(按)="callback_function()"将导致离子列表将无法再滚动.错误与否,我发现我需要添加一个自定义手势指令,它将添加对新属性的支持,在这种情况下我称之为longPress.它工作得很好,除了我没有得到如何添加回调函数:-)
我已经按照教程(http://roblouie.com/article/198/using-gestures-in-the-ionic-2-beta/)
"press-directive"是在src/components/press-directive/press-directive.js中创建的,如下所示:
import { Directive, ElementRef, OnInit, OnDestroy } from '@angular/core';
import { Gesture } from "ionic-angular/gestures/gesture";
/**
* Generated class for the PressDirective directive.
*
* See https://angular.io/docs/ts/latest/api/core/index/DirectiveMetadata-class.html
* for more info on Angular Directives.
*/
@Directive({
selector: '[longPress]' // Attribute selector
})
export class PressDirective implements OnInit, OnDestroy {
el: HTMLElement;
pressGesture: Gesture;
constructor(el: ElementRef) {
this.el = el.nativeElement;
}
public theCallback() {
}
ngOnInit() {
this.pressGesture = new Gesture(this.el);
this.pressGesture.listen();
// instead …Run Code Online (Sandbox Code Playgroud)