In my controller I have some scope variables like
$scope.searchText = "abc";
$scope.currentPage ="1";
$scope.sortBy ="dateTime";
$scope.sortOrder="reverse";
$scope.columnSettings = [
{"name": "dateTime,
"displayName": "Datetime",
"filterText": ""
},
{"name": "name,
"displayName": "Name",
"filterText": "xyz"
},
{"name": "id,
"displayName": "ID",
"filterText": ""
}]
I need to watch on all the $scope variables and "filterText" key of the objects in "columnSettings" array.
I am using
$scope.$watchCollection('[searchText, sortBy, sortOrder, currentPage, itemsPerPage, columnSettings]', function(newVal, oldVal){
// Ignore initial scope change
if(oldVal && newVal !== oldVal){
// watch is triggered for changes in searchText, sortBy etc...
// but not for "filterText" change in columnSettings
}
});
My question is
a) watch is triggered for changes in searchText, sortBy, currentPage etc...but not for "filterText" change in columnSettings. How can I solve this?
b) also, I want to trigger watch only on "filterText" key change and not on any changes to the other keys.
Any help is greatly appreciated.
watchis created for you anyway (this is two-way binding). I'm curious to know why you think you need to watch everything like this. :)