Javascript 自定义表单验证指令没有';无法传递输入数据

Javascript 自定义表单验证指令没有';无法传递输入数据,javascript,forms,angularjs,Javascript,Forms,Angularjs,我编写了一个自定义表单验证指令,它只检查输入的金额是否超过设定的金额。如果是,则通知用户,如果不是,则表单照常提交 我遇到的问题是,当我提交表单时,将数据推送到存储器的控制器没有拾取我输入到输入中的数量 app.directive('customValidation', function() { return { restrict: 'A', require:'ngModel', link: function(scope, elem, attrs, ctrl) {

我编写了一个自定义表单验证指令,它只检查输入的金额是否超过设定的金额。如果是,则通知用户,如果不是,则表单照常提交

我遇到的问题是,当我提交表单时,将数据推送到存储器的控制器没有拾取我输入到输入中的数量

app.directive('customValidation', function() {
return {
    restrict: 'A',
    require:'ngModel',
    link: function(scope, elem, attrs, ctrl) {
        ctrl.$parsers.unshift(function(value) {
            var minimum = ctrl.$viewValue;
            if (minimum > scope.total) {
                ctrl.$setValidity('customValidation', false);
            } else {
                ctrl.$setValidity('customValidation', true);
            }
            return value;
        });
    }
}
});
我明白了

{ "date": "2014-06-17T09:14:51.340Z", "status": false }
而不是这个

{ "amount": 1222, "date": "2014-06-17T09:14:51.340Z", "status": false }
//形式

<form name="removeMoney" ng-submit="removeEntry()" novalidate>

              <label class="error">
                <input
                  type="number"
                  name="subAmount"
                  placeholder="Remove money from wallet"
                  ng-model="subtractAmount"
                  ng-pattern="/^\d{0,9}(\.\d{1,2})?$/"
                  custom-validation />
              </label>

              <small class="error" ng-show="removeMoney.subAmount.$error.customValidation">
                You can't remove more than {{ total | currency:'£' }}
              </small>

              <small class="error" ng-show="removeMoney.subAmount.$error.pattern">
                Please enter values with no/two decimal points only -- 0.00
              </small>

              <button type="submit" ng-disabled="removeMoney.$invalid" class="button postfix alert">Remove</button>

        </form>
//指示

app.directive('customValidation', function() {
return {
    restrict: 'A',
    require:'ngModel',
    link: function(scope, elem, attrs, ctrl) {
        ctrl.$parsers.unshift(function(value) {
            var minimum = ctrl.$viewValue;
            if (minimum > scope.total) {
                ctrl.$setValidity('customValidation', false);
            } else {
                ctrl.$setValidity('customValidation', true);
            }
        });
    }
}
});

我没有返回值。这就是为什么我提交表格时什么也没发生

app.directive('customValidation', function() {
return {
    restrict: 'A',
    require:'ngModel',
    link: function(scope, elem, attrs, ctrl) {
        ctrl.$parsers.unshift(function(value) {
            var minimum = ctrl.$viewValue;
            if (minimum > scope.total) {
                ctrl.$setValidity('customValidation', false);
            } else {
                ctrl.$setValidity('customValidation', true);
            }
            return value;
        });
    }
}
});

他们的控制台有错误吗?如果没有,你能为这个问题设置一个小提琴手吗?没有控制台错误没有。我正在尝试设置一个小提琴。我现在学到的一件事是,当我不使用指令并提交表单时,所有数据都会被传递,表单会正常工作,所以问题肯定出在指令或我使用它的方式上。