javascript Fastclick.js 与 AngularJS 的集成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20427604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 18:27:59  来源:igfitidea点击:

Fastclick.js integration with AngularJS

javascriptangularjscordovatouch

提问by jedd.ahyoung

I'm building a Cordova application and click response times are slow.

我正在构建 Cordova 应用程序并且单击响应时间很慢。

I foundthe angular-touchplugin for Angular (which, while designed for Angular 1.2.0, looks like it would likely work with older versions of Angular, as it's really just a set of directives) but upon trying it out, I didn't get the results I wanted. Clicks still aren't firing on tap.

找到了Angular的angular-touch插件(虽然它是为 Angular 1.2.0 设计的,但看起来它可能适用于旧版本的 Angular,因为它实际上只是一组指令)但是在尝试时,我没有没有得到我想要的结果。点击仍然没有触发。

From what I understand, fastclick.jsis a more stable alternative to angular-touch at the moment (as angular-touch is still in development). I, however, want my ng-clickdirectives to take advantage of fastclick.

据我了解,fastclick.js目前是 angular-touch 更稳定的替代品(因为 angular-touch 仍在开发中)。但是,我希望我的ng-click指令能够利用 fastclick。

How can I integrate fastclick.js with angular - can I just include the file and init the script, or do I have to wrap fastclick behavior in ng-click(essentially what angular-touch does with its first-party code)?

如何将 fastclick.js 与 angular 集成 - 我可以只包含文件并初始化脚本,还是必须将 fastclick 行为包装在ng-click(基本上是 angular-touch 对其第一方代码的作用)?

Note: My app is using Angular 1.0, as it was built before the stable release.

注意:我的应用程序使用的是 Angular 1.0,因为它是在稳定版本之前构建的。

采纳答案by jedd.ahyoung

This was simpler than I thought; I anticipated having to modify some angular directives, but it turns out that this is just a drop-in library. I included it before my angular library and saw instant results in my phonegap application (after calling new FastClickper the fastclick documentation).

这比我想象的要简单;我预计必须修改一些 angular 指令,但事实证明这只是一个插入库。我将它包含在我的 angular 库之前,并在我的 phonegap 应用程序中看到了即时结果(在new FastClick根据 fastclick 文档调用之后)。

So far, I can't find any downsides to this method. I thought that there might be some issues with the document.ready-type setup call (instead of something more integrated into Angular), but there don't seem to be any timing issues or anything.

到目前为止,我找不到这种方法的任何缺点。我认为document.ready-type setup 调用可能存在一些问题(而不是更多地集成到 Angular 中),但似乎没有任何时间问题或任何问题。

Worth noting for anyone who stumbles onto this question - I'm only using the tap functionality; I believe that fastclick exposes some extra functionality that I'm not using for this project.

对于偶然发现这个问题的人来说值得注意 - 我只使用点击功能;我相信 fastclick 公开了一些我没有用于这个项目的额外功能。

回答by Blazemonger

From this page: the "Angular way" is to .runthe FastClick initializer in your Angular JS file. Make sure to load the fastclick.jsmodule before your Angular code.

从此页面:“Angular 方式”.run指向 Angular JS 文件中的 FastClick 初始值设定项。确保fastclick.js在 Angular 代码之前加载模块。

HTML:

HTML:

<script src="js/fastclick.js"></script>
<script src="js/app.js"></script>
<script src="js/filters.js"></script>
<script src="js/controller.js"></script>

in app.js:

在 app.js 中:

app.run(function() {
    FastClick.attach(document.body);
});