1

My json:

name : 'name1'
age : '16'
error : 'some text etc'
address : 'adress details '
etc

My filter:

<div ng-repeat="datalist in datalists | filter:searchquery">
name : {{ name}} etc
</div>
<input type="text"  value="Search" ng-model="searchquery">

Here I don't want to filter error details, error may be a list of objects sometimes.
How can I exclude error field?

I've tried:

<div ng-repeat="datalist in datalists | filter:searchquery && !error">

but that's not working.

Please give me suggestions on how to fix this.

2
  • 1
    Write a custom filter that ignores that property. Commented Jul 29, 2014 at 15:29
  • stackoverflow.com/a/13216282/189756 Commented Jul 29, 2014 at 15:31

1 Answer 1

3
angular.module('dataListFilters', []).filter('excludeErrors', function() {
  return function( data ) {
    if (!data.error ) {
       return data;
    }
  };
});

Then you must include it in your app:

angular.module('yourApp', ['ngRoute','controller','excludeErrors']);

<div ng-repeat="datalist in datalists | filter: excludeErrors | filter: searchquery ">
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.