Last Updated: February 25, 2016
·
1.066K
· bopm

Filtering data in AngularJS controller using $filterProvider

So you have collection and set some properties inside of it. In my case it's selected property.

<input type="checkbox" data-ng-model="point.selected" data-ng-change="selectPoint(point)"/>

And you need to implement check that there is any selected objects in collection:

$scope.selectPoint = function selectPoint(point) {   
  if($filter('filter')($scope.points, {selected:true}, true).length > 0) {
    $scope.nextStepAvailable = true;
  } else {
    $scope.nextStepAvailable = false;
  }
}

So now it possible to set use nextStepAvailable variable to enable/disable submit button.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#angularjs
Did you know?

AngularJS pages are long-lived browser apps with the same script risk as a newer single-page app. Third-party code in the template can read forms and values rendered on the page.

Security insights from Cside