Prashobh
Prashobh

Reputation: 9542

How to exclude some fields from filtering using angular js

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.

Upvotes: 1

Views: 2816

Answers (1)

bencripps
bencripps

Reputation: 2053

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 ">

Upvotes: 3

Related Questions