AngularJS Filter number with fixed length 4

Sometimes you want a number of a certain length. If it’s not of that length it needs leading zeros. AngularJS provides the number filter. However this lacks the possibility to have leading zeros.

AngularJS is very extendable. You can make your own leading zeros filter in just a few minutes. The creation of a custom AngularJS filter needs three things.

  1. Create a module
  2. Create the filter and his function
  3. Register the module in the application

The AngularJS Filter

The JSFiddle belows shows a filter that gives you leading zeros.

Leave a comment

Your email address will not be published. Required fields are marked *

4 thoughts on “AngularJS Filter number with fixed length