Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.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
Javascript AngularJS:ng模型禁用上的调用指令_Javascript - Fatal编程技术网

Javascript AngularJS:ng模型禁用上的调用指令

Javascript AngularJS:ng模型禁用上的调用指令,javascript,Javascript,app.directive('updateCIMALS',函数($parse,$filter){ 返回{ 限制:“A”, 要求:“?ngModel”, 链接:功能(范围、ele、属性、ngModel){ 范围:$watch(函数(){ ngModel.$render=function(){ var decimalDigits=$parse(attrs.updateDecimals)(范围); 控制台日志(小数位数); var updatedValue=parseFloat(ngModel.$vi

app.directive('updateCIMALS',函数($parse,$filter){
返回{
限制:“A”,
要求:“?ngModel”,
链接:功能(范围、ele、属性、ngModel){
范围:$watch(函数(){
ngModel.$render=function(){
var decimalDigits=$parse(attrs.updateDecimals)(范围);
控制台日志(小数位数);
var updatedValue=parseFloat(ngModel.$viewValue,10);
updatedValue=$filter('number')(updatedValue,小数位数);
console.log(updatedValue);
ngModel.$setViewValue(updatedValue);
}
});
}
};

});如果要格式化值,应向ngModel.$formatters添加格式化程序

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

app.controller('MainCtrl', ['$scope', 'filterFilter', 'orderByFilter', function($scope, filterFilter, orderByFilter) {
    $scope.value = 1.23456789;
}]);

app.directive('updateDecimals', function($parse, $filter) {
  return {
    restrict: 'A',
    require: '?ngModel',
    link: function(scope, ele, attrs, ngModel) {
      var decimalDigits = $parse(attrs.updateDecimals)(scope);
      console.log(decimalDigits);
      ngModel.$formatters.unshift(function(v) {
        var updatedValue = parseFloat(v, 10);
        console.log(updatedValue);
        updatedValue = $filter('number')(updatedValue, decimalDigits);
        return updatedValue;
      });
    }
  };
});


如果您想修改模型值,可以使用ngModel.$parsers。类似地。

您能解释一下您的问题吗?您遇到了什么错误<如果我添加ele.on('blur',function(),此函数将调用blur。同样,我必须添加什么来调用函数on disable