1

I have a problem when the attribute of the object does not exist and I can not filter using "!null", I wonder if filter can validate this or i need to create a new filter for this.

Html ng-repeat

 <li ng-repeat="detail in details | filter:{shortDescription: '!null'}">
    <p>{{detail.name}}</p>
 </li>

JavaScript Array

$scope.details = [{
        name: 'Bill',
        shortDescription: null
    },{
        name: 'Bill2',
    }, {
        name: 'Sally',
        shortDescription: 'A girl'
    }];

Result

  • Bill2
  • Sally

Bill2 have no exist shortDescription but not filter.

expected Result:

  • Sally

JSFiddle http://jsfiddle.net/4wxs67yv/28/

AngularJS v.1.3.15

How i can do this?

1

1 Answer 1

1

You could try using double not operator,as

<li ng-repeat="detail in details | filter:{shortDescription: '!!'}">
<p>{{detail.name}}</p>

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

2 Comments

could you update the fiddle with answer jsfiddle.net/4wxs67yv/30 ..its not working here
i want filter but when no exists attribute : result = *Sally

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.