AngularJS Filter Number Fixed Length

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.

  • Create a module
  • Create the filter and his function
  • Register the module in the application

The AngularJS Filter

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

Published under  on .



Hi! I'm Stefan, a software developer based in Utrecht, The Netherlands.