I'm trying to understand where the issue is in my use of $scope.$watch, but I can't figure out why the function defined in the watch is not fired. I have this multiselect in Angular material:
<md-select multiple ng-model="selectedItems" placeholder="Please select">
<md-option ng-repeat="item in specialities" ng-value="item" ng-class="{'selected': item.selected}">
<ng-md-icon class="checkboxfull" icon="check_box" size="18"></ng-md-icon>
<ng-md-icon class="checkboxoutline" icon="check_box_outline_blank" size="18"></ng-md-icon>
{{item.name}}
</md-option>
</md-select>
and in the controller I'm calling the $watch for this view, that should be I soppose selectedItems:
$scope.$watch('selectedItems', function(){
console.log("$scope.selectedItems: ",$scope.selectedItems);
$scope.filter.idList.length = 0;
angular.forEach($scope.selectedItems, function (item) {
$scope.filter.idList.push(item.id);
});
console.log("$scope.filter.idList: ",$scope.filter.idList);
});
But the log is never reached and the $scope.filter.idList is never populated. I saw other examples on stackoverflow that are working with this solution, e.g. AngularJS: $watch for a select input. Thank you for pointing me on the right direction!