I am illustrating a stacked graph along with its table and fetching its json data with $http.get() and setting it to $scope.dataset
html:
<input ng-model="_searchQuery.key1.key2">
<tr ng-repeat="(key, value) in dataset | filter:_searchQuery ">
I how can I update $scope.dataset in controller?
_searchQuery matches dataset and filters my table like charm. no need to code any thing in controller. ie dataset.key1.key2 reflects to _searchQuery.key1.key2
but for my nvd3.js stacked graph I have to filter the $scope.dataset the same way in DOM. $scope.dataset = $filter('$scope._searchQuery.key1.key2')($scope.dataset) throughs an err. Im following angular documentation and this link: How to use a filter in a controller?
It might be a possible duplicate question How do I filter an array with AngularJS and use a property of the filtered object as the ng-model attribute?
same solution worked for me:
first: I had to instantiate
$scope._searchQueryincontrolleras anobjectand include its properties.second: update the
$scope.dataset- and the keyword for filter by object property isfilterwhich I was playing around with_searchQuerythe syntax helped me to fix the problem:
$scope.dataset = $filter('filter')($scope.dataset,$scope._searchQuery.key1.key2);It looks its not possible to pass more than 2 args to $filter, thus to filter based on more inputs I had to copy the same line and pass
$scope._searchQuery.key1.key3to it.