小编Ste*_*use的帖子

Ionic 2 - 为"长按"事件指令设置回调

我试图在元素上添加自定义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)

ionic-framework ionic2 angular

3
推荐指数
1
解决办法
8834
查看次数

标签 统计

angular ×1

ionic-framework ×1

ionic2 ×1