Search code examples
javascriptangularjs-directivemean-stackmeanjsangularjs-ng-change

Angular ng-change not calling code. Am I using wrong model


I am building an app using MEAN.js generators and a tutorial I found online. Here I have a datepicker in one of my Angular views. For now I would like the ng-change directive to be recognized and do something. At the moment when I make a change to the date my test alert shown here does not get called.

<div class="form-group">
   <label class="control-label" for="statusdate">Status Date</label>
   <div class="controls">
      <input type="date"  ng-change="alert('something')" data-ng-model="statusDate" id="statusdate" class="form-control">
   </div>
</div>

Can somebody help? I am new to Angular.

Also, I read somewhere it may be because I used data-ng-model as opposed to ng-model. Could this be the case? If so then what is the difference between the two?


Solution

  • You are executing a method that does not exist in the controller.

    Try creating it like this:

    $scope.alert = function(msg) {
        alert(msg);
     };