Help with <select> ng-change

15,181 views
Skip to first unread message

pablo

unread,
Aug 27, 2012, 1:36:15 AM8/27/12
to ang...@googlegroups.com
I thought this would be simple ...

In FireFox I get an
Error: No controller: ngModel ... 2 dozen lines then
<select ng-change="change">

I added

<select ng-change="change">
      <option value ="1">Week 1</option>
      <option value ="2">Week 2</option>
</select>
<div>counter = {{counter}}</div>

My controller works fine (other ui components bind) here is what I added to my controller

$scope.counter = 1;
$scope.change = function () {
     $scope.counter++;
};

I actually need to do an $http.get when a select list changes.  But for now I would be happy just to get this simple guy working.
From the error Angular obviously doesn't like what I've written.
What am I doing wrong?

P:)

Stephen Pitchford

unread,
Aug 27, 2012, 1:46:02 AM8/27/12
to ang...@googlegroups.com
Without looking too much at it, if you read the documentation on ng-change: http://docs.angularjs.org/api/ng.directive:ngChange it says that ng-change requires ng-model to present on the element. I assume ng-change is used to watch a change on an ng-model value.


here is a working fiddle.

Cheers,
Stephen

pablo

unread,
Aug 27, 2012, 2:03:17 AM8/27/12
to ang...@googlegroups.com
thank you, that works.   I read the docs and it didn't (still does't) mean anything to me.  'select_value'  is an arbitrary name you chose.  Humm..  I'll give the doc's another shot tomorrow.

thanks again 

Stephen Pitchford

unread,
Aug 27, 2012, 2:07:37 AM8/27/12
to ang...@googlegroups.com
Yes, select_value is a random value I chose but in a real scenario it would probably be used to represent the value of the element you are wanting to "watch" with ng-change. From my understanding, ng-change is used to register a users interaction and change of an ng-model value. And then use the function bound to ng-change to do something with the interaction.

Hope everything clears up and makes sense.
Reply all
Reply to author
Forward
0 new messages