Curriculum
Course: AngularJS
Login

Curriculum

AngularJS

AngularJS Tutorial

0/65
Text lesson

Use a Custom Service Inside a Filter

After creating a service and linking it to your application, you can use that service in any controller, directive, filter, or even within other services. To use the service inside a filter, include it as a dependency when defining the filter.

The hexafy service is utilized in the myFormat filter.

app.filter(‘myFormat’,[‘hexafy’function(hexafy) {
  return function(x) {
    return hexafy.myFunc(x);
  };
}]);

You can apply the filter when displaying values from either an object or an array.

<ul>
  <li ng-repeat=”x in counts”>{{x | myFormat}}</li>
</ul>