Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
angularjs中输入字段的自定义货币过滤器_Angularjs - Fatal编程技术网

angularjs中输入字段的自定义货币过滤器

angularjs中输入字段的自定义货币过滤器,angularjs,Angularjs,如何使用angularjs将值格式化为印度货币类型。 例如,454565到454565.00 我有如下输入字段: <input type="text" ng-model="item.cost /> 您可以按如下方式为其创建指令 HTML 链接将价格定制为什么?提供更多有关exmaple将值从454565转换为454565.00的信息 function FormatMyNumber(yourNumber) { // Limit to two decimal places

如何使用angularjs将值格式化为印度货币类型。 例如,454565到454565.00

我有如下输入字段:

<input type="text"  ng-model="item.cost />  

您可以按如下方式为其创建指令

HTML


链接

将价格定制为什么?提供更多有关exmaple将值从454565转换为454565.00的信息
function FormatMyNumber(yourNumber) {
    // Limit to two decimal places 
    yourNumber = parseFloat(yourNumber).toFixed(2);
    //Seperates the components of the number
    var n = yourNumber.toString().split(".");
    //Comma-fies the first part
    n[0] = n[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    //Combines the two sections
    return n.join(".");
}

FormatMyNumber(454565); //yields 454,565.00
  <div ng-app="myApp">
    <div ng-controller="myCtrl">
      {{amount}}
      <input format-to-currency amount="amount">
    </div>
  </div>
  angular.module('myApp', [])
    .controller('myCtrl', function($scope) {
      $scope.ampunt = 2;
    })
    .directive('formatToCurrency', function($filter) {
      return {
        scope: {
          amount: '='
        },
        link: function(scope, el, attrs) {
          el.val($filter('currency')(scope.amount));

          el.bind('focus', function() {
            el.val(scope.amount);
          });

          el.bind('input', function() {
            scope.amount = el.val();
            scope.$apply();
          });

          el.bind('blur', function() {
            el.val($filter('currency')(scope.amount));
          });
        }
      }
    });