简体   繁体   English

如何在ionic 4中添加/导入/安装Gesture?

[英]How to add / import / install Gesture in ionic 4?

I try to create sliding segments using this example. 我尝试使用此示例创建滑动段 This example in ionic 3 and I want to make it work for ionic 4 and in this example, he is using Gesture. 此示例在ionic 3中,我想使其适用于ionic 4 ,在此示例中,他正在使用Gesture。 But the problem is I am not able to import Gesture. 但是问题是我无法导入手势。

in example imported this Ionic v3: 在示例中导入了该Ionic v3:

import { Gesture } from 'ionic-angular/gestures/gesture';

so as we importing other @ionic/angular but showing error: 所以当我们导入其他@ionic/angular但显示错误时:

import { Gesture } from '@ionic/angular/gestures/gesture';

Error: Cannot find module '@ionic/angular/gestures/gesture'.ts(2307) 错误:找不到模块'@ ionic / angular / gestures / gesture'.ts(2307)

In short, I just want to import gestures in my ionic 4 projects . 简而言之,我只想在ionic 4项目中导入手势。 Please help. 请帮忙。

The Ionic team is working on adding gesture support to Ionic v4 right now. Ionic小组正在努力为Ionic v4添加手势支持。 See this issue in on Github and especially this comment . 在Github上可以看到这个问题 ,尤其是这个评论

Ionic is moving from HammerJS-based gestures towards a custom solution, so I'd either subscribe to the issue above and wait for the feature to be completed or you can install and use HammerJS . Ionic正在从基于HammerJS的手势转向自定义解决方案,因此我要么订阅上面的问题,然后等待功能完成,要么安装并使用HammerJS

Latter is described in detail here . 这里详细介绍。 First, you need to install HammerJS via npm: 首先,您需要通过npm安装HammerJS:

npm install hammerjs

Then you'll have to add the following import to your main.ts : 然后,您必须将以下导入添加到main.ts

import 'hammerjs';

Then you should be able to use gesture bindings, as you're used to, eg: 然后,您应该能够像以前那样使用手势绑定,例如:

<div (swipe)="onSwipe($event)"></div>

The blog post mentioned above offers some more examples and also a list of available events . 上面提到的博客文章提供了更多示例,还提供了可用事件列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM