angularjs 货币过滤器在前面添加额外的加号

angularjs currency filter add extra plus symbol in front

我在 html.

中按以下方式使用过滤器
var mydata = 20000;

{{mydata | currency : '$' : 2}}

然而,该值显示为 +20,000.00 它的值多了一个“+”。

有办法去除吗?

谢谢!

需要覆盖 $locale 数字格式。

appRun.$inject = ['$locale'];
function appRun ($locale) {
  $locale.NUMBER_FORMATS.PATTERNS[1].posPre = '$';
}

检查以确保您没有覆盖代码中某处的默认货币符号。请参阅以下示例。

script.js

var app = angular.module('root', []);

app.run(["$locale", function ($locale) {
  $locale.NUMBER_FORMATS.CURRENCY_SYM = "+"
}]);

app.component('root', {
  template: `
  <div>
    <!-- Prints out ,000 -->
    {{ $ctrl.myData | currency: "$": 2 }}
  </div>
  <div>
    <!-- Prints out +20,000 -->
    {{ $ctrl.myDataPlus | currency }}
  </div>
  `,
  controller: function() {
    this.myData = "20000";
    this.myDataPlus = "20000";
  }
});

index.html

<html ng-app="root">
  <head>
    <script data-require="angular.js@*" data-semver="1.5.8" src="https://code.angularjs.org/1.5.8/angular.js"></script>
    <script src="script.js"></script>
  </head>

  <body>
    <root></root>
  </body>

</html>