简体   繁体   English

Fastclick.js与AngularJS集成

[英]Fastclick.js integration with AngularJS

I'm building a Cordova application and click response times are slow. 我正在构建Cordova应用程序,并且单击响应时间很慢。

I found the angular-touch plugin 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. 找到了Angular的angular-touch插件(虽然为Angular 1.2.0设计,看起来它可能适用于Angular的旧版本,因为它实际上只是一组指令)但是在尝试之后,我没有'得到我想要的结果。 Clicks still aren't firing on tap. 点击仍然没有点击。

From what I understand, fastclick.js is a more stable alternative to angular-touch at the moment (as angular-touch is still in development). 根据我的理解, fastclick.js是目前角度触摸更稳定的替代品(因为角度触摸仍在开发中)。 I, however, want my ng-click directives to take advantage of fastclick. 但是,我希望我的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集成 - 我可以只包含文件并初始化脚本,还是必须在ng-click包含fastclick行为(基本上是angular-touch对其第一方代码的作用)?

Note: My app is using Angular 1.0, as it was built before the stable release. 注意:我的应用程序使用的是Angular 1.0,因为它是在稳定版本之前构建的。

From this page : the "Angular way" is to .run the FastClick initializer in your Angular JS file. 这个页面 :在“角办法”是.run的FastClick初始化在角JS文件。 Make sure to load the fastclick.js module before your Angular code. 确保在Angular代码之前加载fastclick.js模块。

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);
});

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 FastClick per the fastclick documentation). 我将它包含在我的角度库之前,并在我的phonegap应用程序中看到了即时结果(根据fastclick文档调用new 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设置调用可能存在一些问题(而不是更集成到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暴露了一些我没有用于这个项目的额外功能。

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

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