jtrussell / angular-snap.js

AngularJS directive for snap.js
http://jtrussell.github.io/angular-snap.js/
MIT License
700 stars 69 forks source link

ngMobile and snapRemote incompatible on a phonegap app? #23

Closed dbaq closed 11 years ago

dbaq commented 11 years ago

Hi folks,

If I am using ngMobile (http://code.angularjs.org/1.1.5/docs/api/ngMobile.directive:ngClick) and snapRemote, I cannot use the snapRemote service in my controller with angular js 1.1.5 and phonegap.

the following code works on a web browser but does not work when I am launching my app with phonegap on android or iOS.

here is the HTML : <a class="button" ng-click="toggleMenu()">Toggle</a>

here is my JS : $scope.toggleMenu = function() { // some code.. snapRemote.toggle('left'); console.log('toggle menu'); }

Without ngMobile, it is perfectly working but with ngMobile : angular.module('module', ['ngMobile', 'snap'])

it is not working, no errors, nothing. Is ngMobile stopping the event? Am I missing something? why is it working on a web browser and not on phonegap?

Is there a possibility to enable taping with snapRemote? I don't really care about ngMobile.

thanks for your help.

revolunet commented 11 years ago

Use FastClick from ftlabs instead or ngMobile. NgMobile is buggy

jtrussell commented 11 years ago

Are you seeing any console output at all? I.e. does 'toggle menu' get written or is it not even getting that far? I ask because I've seen issues with ngMobile sending multiple click events so it may be possible the toggle method is getting called twice for a quick open/close. This plunk uses ngMobile (though I don't have much experience with it so let me know if I set it up incorrectly) and seems to behave as I'd expect.

I can't speak to ngMobile in particular but I have seem enough nasty bugs on the unstable branches of angular to be wary. If you can give FastClick a shot as @revolunet suggests I'd be curious to see if that clears things up for you.

Gwash3189 commented 11 years ago

Hey @dbaq , @jtrussell is correct. I am currently building an app with Phonegap & angular-snap. Fastclick does work as it should. I'm not 100% sure why ng-tap does not work, but then again, it is an unstable branch of angular for a reason.

dbaq commented 11 years ago

Hi guys,

thanks for your help, you are great!

@jtrussell : I have downloaded your plunk as a zip then launched it on a local server with : python -m SimpleHTTPServer then I used that chrome extension : http://emulate.phonegap.com/ so I was able to emulate a device. So it is really buggy, the toggle with snapRemote works really randomly, like 1 over 10 times =/ Also, I can see foobar in the console everytime I am clicking.

I tried fastclick and it is working like a charm.

I am closing that issue because it's not related to angular-snap.js but to ngMobile.

michalc commented 10 years ago

For anyone who wants to get this working with ngTouch (the renamed ngMobile), I've found a workaround. You need to call preventDefault on the original event produced by the click.

In the template:

ng-click="toggleMenu($event)"

and in the handler

$scope.toggleMenu = function(event) {
  event.preventDefault();
  snapRemote.toggle('left');
}

As this is tinkering with DOM events, it would be usual to keep this in a directive (I've created by own mySnapToggle directive to handle this, for example).