0

I have suchc filter:

  .filter('searchFilter', function() {
    function contains(src, value, except) {
      var key;
      switch(typeof src) {
        case 'string':
        case 'number':
        case 'boolean':
          return String(src).toLowerCase().indexOf(value.toLowerCase()) > -1;
        case 'object':
          except = except || [];
          for(key in src) {
            if( src.hasOwnProperty(key) &&
                except.indexOf(key) < 0 &&
                contains(src[key], value, except)
            ) {
              return true;
            }
          }
        default:
          return false;
      }
      return false;
    }

    return function(data, filter, except) {
        return filter ? data.filter(function(item) {
          return contains(item, filter, except);
        }) : data.slice(0);
    };

and if i'm working in controller i have:

$filter('searchFilter')($scope.users, $scope.search, ['Id','ImgUrl']);

but now i need to put it on view with ng-repeat, and i try so:

<li ng-repeat="node in users | searchFilter:users:search:['Id', 'ImgUrl']"></li>

but it work bad...

if i put debugger before line return filter ? data.filter(function(item) { i see, that my filter is not my search word, by array-data...

how to solve this?

0

1 Answer 1

1

Use

<li ng-repeat="node in users | searchFilter:search:['Id', 'ImgUrl']"></li>

You dont have to pass users this way searchFilter:users:search:['Id', 'ImgUrl']".users will automatically will be passed as first parameter.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.