Lately I've been using the ControllerAs syntax, but I'm not sure how I'm able to change a model from my controller within a $watch.
My watch is like this:
$scope.$watch(angular.bind(this, function () {
return this.allItemsSelected;
}), function (value) {
//
})
In my view I got a model called pages.selectedItems. pages is the alias for my PagesController.
I've tried $scope.selectedItems, selectedItems andd this.selectedItems so far, but it won't work. Also I've wrapped it in the angular.bind but didn't work as well.
Anybody had this problem as well and can provide a solution?
EDIT
I'm using the checklist-model directive so the model in the ngRepeat is checklist-model="pages.selectedItems". The allItemsSelected variable is a model from a checkbox. If its true I have to loop through my data and add the ids to the selectedItems array.
allItemsSelected? if it is an object use third argument in your watch astruefor object equality, if it is an array usewatchCollectionallItemsSelectedin your case? Can you show us the rest of your controller? The code you've shown us appears to be correct so the problem is surely in something you haven't shown us.allItemsSelectedis a boolean from a checkbox. If its true I have to add all theitemsin theselectedItemsvariable as array.{{pages.selectedItems}}I can see the array being modified, but in my controller I can't modify it for some reason.