Just declare a filter and a service in your angular module like this:
angular.module('myModule')
.service('myFilterService', function () {
this.mySharedCode = function () {
// Put your shared code here
};
})
.filter('myFilter1', function (myFilterService) {
return function (input, arg) {
if (typeof input !== 'undefined') {
// Do your filtering using myFilterService
myFilterService.mySharedCode(...)
return myFilteredInput
} else {
return myReturnValueIfInputUndefined;
}
}
})
.filter('myFilter2', function (myFilterService) {
// Do your filtering using myFilterService like you did with myFilter1
})
Assuming you have an item
available on the scope, you can use your filter
In your controllers:
.controller('myController', function ($scope, $filter) {
var filteredItem = $filter('myFilter')($scope.item, filterArg);
}
In your templates:
{{ item | myFilter : filterArg }}