Reputation: 3651
I have a custom function that returns true or false
controller function:
this.isStoreEquipment = function(equipment){
var returnVal = false
if (Array.isArray(equipment)){
equipment.forEach(function(piece, index, array){
if (Config.myEquipment().indexOf(piece)!= -1){
returnVal = true
return
}
});
}
return returnVal
}
and in my table
<tr ng-cloak id="{{$index}}"
ng-repeat-start="equipment in currentController.storeEquipment | orderBy: '-lastService ' | filter: currentController.isStoreEquipment(equipment.storeNum))>"
<td>{{equipment.lastService | date:'MM/dd/yyyy'}}</td>
<td>{{equipment.type}}</td>
<td>{{equipment.name}}</td>
<td>{{equipment.storeNum}}</td>
</tr>
Now I have validated that this does return true by adding a <td>currentController.isStoreEquipment(equipment.storeNum)
to my table and it is returning true and false like it should, HOWEVER i am not getting any results with the filter applied to my ng-repeat expression.
Upvotes: 0
Views: 126
Reputation: 641
You should register filters like this:
angular.module('test').filter('inStore', function() {
return function(input) {
....
}
});
They're usually more general functions, usable in more than one controller. That said, the input
is the value on which you're applying the filter. In this case it's an array and the filter should return a new array with only the 'good' items.
Here's a nice example https://stackoverflow.com/a/15197233/3927379
Upvotes: 2