How to check if a filter exists in AngularJS

Home / AngularJS / How to check if a filter exists in AngularJS


This article shows how to check if a filter exists in AngularJS

In some cases it may be required to check if a filter is defined in your AngularJS application.
This might especially be the case when writing reusable components.

Initial setup

First let’s create a very simple AngularJS application with a filter:

The check

Now that we have our test application, we can check if the filter ‘upper’ exists:

Beyond the concept

We could use this technique to poly-fill missing functionality which is required by one of our pluggable directives or services. A fully functional example can be found here on Plunker.