Firefox上的Angular JS脚本在IE 11上不起作用

时间:2018-10-24 06:23:10

标签: javascript angularjs

我正在尝试使用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)">

1 个答案:

答案 0 :(得分:1)

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