ionic生效swipe事件

0
136

群里的朋友提供的方法,还没验证过

npm install hammerjs –save && npm install @types/hammerjs –save-dev
创建MyHammerConfig.ts
import { HttpClient } from ‘@angular/common/ http’; //空格去掉
import { Injectable } from ‘@angular/core’;
import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from ‘@angular/platform-browser’;
import * as Hammer from ‘hammerjs’;
@Injectable()
export class MyhammerconfigProvider extends HammerGestureConfig {
overrides = {
‘swipe’: { direction: Hammer.DIRECTION_ALL } }
}

在你的app.module文件引入该文件,并在providers里加入以下代码

import { MyhammerconfigProvider } from ‘../providers/myhammerconfig/myhammerconfig’;
import { HAMMER_GESTURE_CONFIG } from ‘@angular/platform-browser’;
//上下滑动
{ provide: HAMMER_GESTURE_CONFIG, useClass: MyhammerconfigProvider }

html可以通过swipeEvent方法就可以监听到向上和向下的滑动了。

留下一个答复

Please enter your comment!
Please enter your name here