Watch a set of select-elements and sum up their id's

86 Views Asked by At

I have a list of select-elements and would like to assure that at least one of them has a value selected. I have made a small fiddle,

http://plnkr.co/edit/bLh5Gp7fsLphjX0hcLSB?p=preview

$scope.$watch('vm.list', function(a, b) {
  alert('changed');
});

where I illustrated the problem. As seen there, I can a) not make a set value to be selected, and b) there's no event firing when one of the options are changed. I would like a button to be hidden if all of the select-boxes are not having any value, hence my question.

1

There are 1 best solutions below

2
On BEST ANSWER

you can use ng-change directive for this

<select ng-change='myScopeFunction()' ng-model="item.value" ng-options="option.id as option.title for               option in vm.options track by option.id">
  <option value>Default</option>
</select>

if you want use $watch, try this one

  $scope.$watch('vm.list', function(a, b) {
    alert('changed');
  },1);

plunker