javascript - Angular JS 脚本适用于 Firefox,不适用于 IE 11

标签 javascript angularjs

我正在尝试使用Angular js实现自定义验证。

以下代码在 FireFox 上完美运行,但 IE 11 抛出错误

Expected ':'

对于行return range.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 语法,IE 不支持它。您需要集成 Babel 或简单更改 scope.valFunc({value: value})

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

相关文章:

javascript - 如何测试 Angular 模块的配置功能?

javascript - 为什么它推送参数名称而不是元素? JavaScript

javascript - javascript中如何通过引用传递参数

javascript - 如何在 Angularjs 中分割日期和时间?

javascript - 为什么在 Angular 中,当我们不分配函数时,作用域属性的变化不会动态地反射(reflect)回 View ?

angularjs - Angular-ui-bootstrap 模式和 typescript

javascript - 使用 AngularJS 模板实现用户生成的 JavaScript 进行计算

javascript - 将字符串解码为 HTML 在 ui-grid Angularjs 中不起作用

javascript - 语法错误: Unexpected token using async and babel in koa

javascript - 更改 Angular ui.grid 中的 MenuItem 图标