Search code examples
angularjsangular-filters

Angular-filter omit with dynamic element from scope


JS: var MyApp = angular.module('SOFdemo',['angular.filter']); MyApp.controller('SOFCtrl',['$scope','$resource','$location',function($scope,$resource,$location){ $scope.serverSizeOptions = [ {"name":"20 Users","value":20}, {"name":"30 Users","value":30}, {"name":"40 Users","value":40}, {"name":"50 Users","value":50}, {"name":"60 Users","value":60}, {"name":"70 Users","value":70}, {"name":"80 Users","value":80}, {"name":"90 Users","value":90}]; }]); I want to display on a table the possible options for a customer that subscribe to a max and min size. I'm using the directive angular-filter

I assigned the controller to my body.

The following ng-repeat directive usage on my partial HTML working well for a tr: < tr ng-repeat="(key,value) in (serverSizeOptions | omit: value<20 | omit: value>50)"> < td>{{key}} < td>{{value}} < /tr>

Now, I would like to change 20 or 50 by my project size like:

< tr ng-repeat="(key,value) in (serverSizeOptions | omit: value<20 | omit: value> project.size.value)"> ...

But here, filter is not applied and I have all my list. project.size.value is on my current scope. I tried several configuration since hours and I'm starting to think that it's not possible to do what I'm expecting.

Any help will be appreciate.


Solution

  • You can use the filterFilter and define a function on your scope, that selects the valid values.

    ng-repeat = "item in serverSizeOptions | filter:myFunction"

    $scope.myFunction = function(item) { ..your logic here return a boolean }