mdv
mdv

Reputation: 945

Using angularJS currency filter directly in JavaScript

I need to use AngularJS currency filter {{value | currency }}, but I dont want to include the whole library only for that. Is there any way to use that filter only directly on html or JavaScript?

Thanks in advance.

Upvotes: 1

Views: 742

Answers (1)

Tyler.z.yang
Tyler.z.yang

Reputation: 2450

In your html:

{{ currency_expression | currency : symbol : fractionSize}}

In your javascript angular controller:

$filter('currency')(array, expression)

Without controller, you can use $injector to get $filter:

var $injector = angular.injector(['ng']);
$filter = $injector.get("$filter");
var result = $filter('currency')(array, expression);

Upvotes: 2

Related Questions