5

EDIT The code is all correct, the problem was because of including 'ngTouch', see my own answer below.

I am probably making some stupid mistake here, but for the life of me I cannot find it. I have this piece of markup, which is correctly wired up with a controller:

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

The controller code:

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

The problem is nothing happens when I click the button. If I change the input field, I get the alert, so ng-change works, but ng-click does not. Let me know if this is not enough information, but I would not know what else to provide, and the general setup seems to be working fine...

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

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

and the controller is defined like this:

angular.module('myModule')
    .controller('StuffCtrl', function ($scope) {
        // above code
    });
5
  • Try to turn the button (with default type submit) into a simple button using <button type="button"...> Commented Apr 15, 2015 at 15:21
  • That should work, can you post a larger snipper of the HTML file and your controller code? Commented Apr 15, 2015 at 15:21
  • Works here - jsfiddle.net/HB7LU/12867 Commented Apr 15, 2015 at 15:21
  • You'll need to provide more context. It's working here too plnkr.co/edit/2Cs4RzEcuNQR6qEIe99q?p=preview Commented Apr 15, 2015 at 15:24
  • No declaration of ng-controller="StuffCtrl" in the HTML ? Commented Apr 15, 2015 at 15:30

1 Answer 1

5

It turned out that the problem was with another dependency 'ngTouch'. I did not use it, but still it was loaded. My module did not even depend on it. (I am using that admin site template from here: http://startangular.com/product/sb-admin-angular-theme/). After removing loading of the ngTouch it worked as expected. I will file this as a bug to both projects as well... Thanks for your help!

Sign up to request clarification or add additional context in comments.

3 Comments

Wow, I just wasted 2 hours troubleshooting this same problem before I found your answer! I would have never figured that out, thank you!!
Thanks for posting this. Been banging my head on the wall here.
Thanks for posting your result. I wasted a few hours - and a few minutes to find that damn ngTouch dependency in the lazy loaded modules...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.