I found this thread looking for thoughts on the following: *when is it
better to use ng-change versus a $watch on the model?*
Right now I'm looking at code in which we *$watch* multiple properties
within an object and call the same function when any of them changes (I
assume this is more efficient than watching the whole object?). Here's
some pseudocode (I don't think a plnkr is necessary here):
var updateSettings = function () {
// do some stuff that involves the whole someOptions object
};
scope.dropdownChoices = { 'optionName1': 0, 'optionName2': 1 };
scope.someOptions = {
checkboxChoice: true,
dropdownChoice: 0
};
scope.$watch('someOptions.checkboxChoice', updateOptions);
scope.$watch('someOptions.dropdownChoice', updateOptions);
With HTML like:
<label><input type="checkbox" ng-model="someOptions.checkboxChoice">
whatever</label>
<select ng-model="someOptions.dropdownChoice" ng-options="key for (key,
value) in dropdownChoices" />
...What if I just added *ng-change* to the input elements instead? (In the
actual code, we have more than one checkbox and dropdown, plus some radio
buttons.)
Thanks,
M
On Tuesday, April 30, 2013 at 9:50:37 AM UTC-7, Mauro Sanna wrote:
>
> I'm using ng-change on a select:
>
> http://plnkr.co/edit/dnySXwv7EX3PdHtJXQKa?p=preview
>
> I want try $watch but the code does not work.
>
> $scope.$watch('selected', function (selected) {
> $scope.selectedList.push(selected);
> });
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.