1
我試圖改變ngModel(input type =「number」)格式。 When there is no decimal the Output must be: 25,00
。如您所見,此代碼在angularjs 1.2.23版本中運行良好,但在1.6.4版本中不起作用。其他解決方案?自定義指令更改輸入類型數字格式,當沒有小數
var app= angular.module('myApp',[]);
app.controller('myCtrl',function($scope){
$scope.test=25;
})
.directive('price', function($filter) {
return {
restrict: 'A',
require: '?ngModel',
link: function(scope, element, attrs, ngModel) {
ngModel.$formatters.push(function (value) {
return $filter('number')(value,2);
});
}
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<input type="number" ng-model="test" step=".01" price>
</div>