I have the following setup
$scope.array =
[
{propertyA: "test",
propertyB: {
propertyC: [true, true, false]
}
},
{propertyA: "test2"},
{propertyA: "test3"}
]
and then
<div ng-repeat="item in array| filter :{propertyB: ''} :true">
{{item.propertyA}}
</div>
So the problem is:
this setup does not display anything
if i change to |filter :{propertyB: '!!'} :true
it does not display anything
if i change to |filter :{propertyB: undefined} :true
it displays everything
I can`t figure it out.
Target: I want to display the items which have the propertyB
undefined and in other case the other way around.
Edit 1: If I iterate over the array with angular.equals(item.propertyB, undefined)
I get false, true, true
Edit 2: jsfiddle UPDATED
Edit 3: I have updated the question
$scope.array =
[
{propertyA: "test", propertyB: "test2"},
{propertyA: "test2"},
{propertyA: "test3"}
];
$scope.filteredArray =[];
angular.forEach($scope.array,function(eachData){
if(angular.isUndefined(eachData.propertyB))
$scope.filteredArray.push(eachData);
});
And the $scope.filteredArray
is array you want and you can use it in repeat for binding in html.
you are adding a filter
on ng-repeat
so you will get a collection
, as input to the filter, instead of a single array element so your implementation will not work.
as Kunal mentioned, try filtering the array before hand and repeat on filtered array.
or add a filter inside double curly braces {{}}
.
check this plnkr
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With