0

I was wondering how I can filter an array to show only results if a property in the array is empty. I have tried the following but to no avail:

<tr ng-repeat="performanceOrder in performanceOrders | filter: salesId.length === 0">

I only want to show results if salesId is empty, is this possible?

Edit

salesId is a property of performanceOrder

performanceOrder: {
    salesId: "S273626",
    status: "Open",
    ...
}
3
  • 1
    define empty , undefined or other? Commented Dec 11, 2013 at 16:33
  • Try == instead of ===, it might be comparing a string to an int. Commented Dec 11, 2013 at 17:20
  • @charlietfl not undefined, just an empty string, so "" Commented Dec 11, 2013 at 18:15

2 Answers 2

1

With ngShow:

<tr ng-show="!salesId.length" ng-repeat="performanceOrder in performanceOrders">

With ngIf:

<tr ng-if="!salesId.length" ng-repeat="performanceOrder in performanceOrders">
Sign up to request clarification or add additional context in comments.

3 Comments

show and filter do different things...can't get a filter count for example with this approach
Yeah, I wasn't sure where salesId comes from. It doesn't look like as a part of performanceOrders, so I figured if salesId is empty ng-repeat shouldn't run at all.
@OlivérKovács salesId is a property on a performanceOrder, so I don't think ng-show and ng-if apply, as it needs to be a filter
0

You can use a function inside the filter like this:

<tr ng-repeat="performanceOrder in performanceOrders | filter: myFilter()>

Then, in your corresponding controller, you can do something like:

$scope.myFilter = function (val) {
  return val.salesId.length === 0;
}

1 Comment

@BiffBaffBoff Remove () from myFilter().

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.