我正在尝试使用angular js实施自定义验证。

以下代码可在FireFox上完美运行,但是IE 11会引发错误


  预期的':'


对于return scope.valFunc({value});

有什么想法可以解决IE的问题吗?
谢谢。

指示:

crudApp.directive('customValidationFunction', function()  {
    return {
        restrict: 'A',
        require: 'ngModel',
        scope: {
            valFunc: '&customValidationFunction'
        },
        link: function(scope, element, attrs, controller)  {
            const normalizedFunc = function(modelValue, viewValue) {
                const $value = modelValue || viewValue;
                return scope.valFunc({$value});
            };
            controller.$validators.customValidationFunction = normalizedFunc;
        }
    };
});


验证功能:

 //custom validation test
    $scope.custValidationFunc = function($value) {
        if (!$value) {
            return true;
        }
        const lowVal = String($value).toLowerCase();
        return lowVal.indexOf("arnold") === -1 && lowVal.indexOf("sylvester") === -1;
    }


HTML:

<input type="text" class="form-control" id="i_position" name="i_position" aria-describedby="i_position_help" placeholder="Enter your Position" ng-model="position"  custom-validation-function="custValidationFunc($value)">

最佳答案

scope.valFunc({value})是ES6语法,I​​E不支持。您需要集成Babel或对scope.valFunc({value: value})进行简单更改

关于javascript - Firefox上的Angular JS脚本在IE 11上不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52962191/

10-12 00:12
查看更多