AngularJS ng-click does not work, but ng-change when calling the same function

EDIT The code is correct, the problem is with the inclusion of "ngTouch", see my own answer below.

I’m probably making some kind of stupid mistake, but for life I can’t find me. I have this piece of markup that is correctly connected to the controller:

<input type="text" ng-change="doStuff()" ng-model="stuff"/> <button ng-click="doStuff()">doStuff</button> 

Controller Code:

 console.log('Hi from controller'); $scope.stuff = "something"; $scope.doStuff = function() { alert('doing stuff'); } 

The problem does not occur when I press the button. If I change the input field, I get a warning, so ng-change works, but ng-click does not work. Let me know if this is not enough, but I don’t know what else needs to be provided, and the general setup seems to work fine ...

The rest of the HTML does not contain any Angular directives, and it loads like this in myModule.config:

 $stateProvider .state('stuff', { templateUrl: 'pages/stuff.html', url: '/stuff', controller: 'StuffCtrl' }) 

and the controller is defined as follows:

 angular.module('myModule') .controller('StuffCtrl', function ($scope) { // above code }); 
+5
source share
1 answer

It turned out that the problem is related to another dependency of 'ngTouch'. I did not use it, but still it was downloaded. My module was not even dependent on it. (I use the admin template template here: http://startangular.com/product/sb-admin-angular-theme/ ). After removing the ngTouch boot, it worked as expected. I will write this as an error for both projects ... Thanks for your help!

+5
source

All Articles