JSFiddle中未调用的函数

时间:2018-07-18 14:46:54

标签: angularjs jsfiddle

在这个JSFiddle中似乎没有一个函数被调用- http://jsfiddle.net/2x4yt0vb/11/

有用于验证的功能和清除功能。没有任何验证有效。例如,如果以“无效条目”形式输入-20或aaa,则应显示其他错误消息。单击“清除”按钮时,clear()函数中的所有功能均未激活。这些功能为什么在JSFiddle中不起作用?

这是HTML:

<html ng-app="myApp">
<div ng-controller="formulaCtrlr" >
<form name="vm.formContainer.form" autocomplete="off">
                          <div class="form-group" ng-class="{'has-error': vm.formContainer.form.FatA.$dirty && vm.formContainer.form.FatA.$invalid}">
                            <label for="FatA" class="col-sm-2 control-label">Fat A</label>
                            <input name="FatA" type="text" class="form-control col-sm-10 input-sm" ng-required="true" ng-model-options="{updateOn: 'blur'}" ui-validate="{numberCheck: 'vm.numberCheck($value)', fatRangeCheck: 'vm.fatRangeCheck($value)'}" ng-model="vm.formulaInput.Fats[0]" /><span>%</span>
                            <span class="error" ng-show="vm.formContainer.form.FatA.$dirty && vm.formContainer.form.FatA.$invalid">Invalid entry.</span>
                            <span class="error" ng-show="vm.formContainer.form.FatA.$dirty && vm.formContainer.form.FatA.$error.numberCheck">{{vm.errorMessages.numberCheck}}</span>
                            <span class="error" ng-show="vm.formContainer.form.FatA.$dirty && vm.formContainer.form.FatA.$error.fatRangeCheck">{{vm.errorMessages.fatRangeCheck}}</span>
                        </div>
                        <div class="form-group" ng-class="{'has-error': vm.formContainer.form.FatB.$dirty && vm.formContainer.form.FatB.$invalid}">
                            <label for="FatB" class="col-sm-2 control-label">Fat B</label>
                                <input name="FatB" type="text" class="form-control col-sm-10 input-sm" ng-required="true" ng-model-options="{updateOn: 'blur'}" ui-validate="{numberCheck: 'vm.numberCheck($value)', fatRangeCheck: 'vm.fatRangeCheck($value)'}" ng-model="vm.formulaInput.Fats[1]" /><span>%</span>
                                <span class="error" ng-show="vm.formContainer.form.FatB.$dirty && vm.formContainer.form.FatB.$invalid">Invalid entry.</span>
                                <span class="error" ng-show="vm.formContainer.form.FatB.$dirty && vm.formContainer.form.FatB.$error.numberCheck">{{vm.errorMessages.numberCheck}}</span>
                                <span class="error" ng-show="vm.formContainer.form.FatB.$dirty && vm.formContainer.form.FatB.$error.fatRangeCheck">{{vm.errorMessages.fatRangeCheck}}</span>
                        </div>
                            <div class="col-sm-offset-2">
                                <input type="reset" value="Clear" class="btn btn-default" ng-click="vm.clear()" ng-disabled="vm.formContainer.form.$pristine" />
                            </div>                        
</form>
        <div>formula input: {{vm.formulaInput}}</div>
</div>        
</html>

这是JS / Angular:

angular.module('myApp', [])
    .controller("formulaCtrlr", ['$scope', function ($scope) {
            var vm = this;

        vm.formContainer = {
            form: {}
        }

        vm.formulaInput = {};
        vm.formulaInput.Fats = [];

        vm.clear = function () {            
            vm.formulaInput = {};
            vm.formulaInput.Fats = [];
            vm.formContainer.form.$setPristine();
        }

        vm.errorMessages = {
            numberCheck: 'Value must be a number.',
            fatRangeCheck: 'Number must be between 0 and 100.'
        }

        vm.numberCheck = function (value) {
            var result = !(isNaN(parseFloat(value)));
            return result;
            //return !(isNaN(parseFloat(value)));
        }       

        vm.fatRangeCheck = function (value) {
            var result = (value && value > 0.0 && value < 100.0);
            return result;
            //return (value && value > 0.0 && value < 100.0);
        }               

  }]);

0 个答案:

没有答案