Skip to content Skip to sidebar Skip to footer

How Can I Use An Angular Js Filter To Format Values In An Array

I've used angular filters to do all kinds of fun formatting, but always on primitive values. For example, filtering numbers into a currency format. How would I do that same kind of

Solution 1:

The currency filter applies to a single value. If you want a filter that applies to an array, you need to add your own, such as:

angular.module('yourModule')
.filter('currenyArray', function($filter) {
  returnfunction(input, uppercase) {
    input = input || [];
    var out = [];
    for (var i = 0; i < input.length; i++) {
      out.push($filter('currency')(input[i]))
    }
    return out;
  };
})

However this will return an array. If you do want to write the array, you need to adapt the function to compute a string instead of an array.

Post a Comment for "How Can I Use An Angular Js Filter To Format Values In An Array"