【问题标题】:Angular syntax error occuring in IE browser only [duplicate]仅在 IE 浏览器中出现 Angular 语法错误[重复]
【发布时间】:2019-06-28 05:15:45
【问题描述】:

我的 Angular 项目中有一小段 JavaScript 代码,在 IE 11 中运行时会引发语法错误,但在 Chrome 中运行良好。在加载页面上什至没有调用这个函数,但仍然抛出错误。

如果我将其注释掉,页面加载正常。

它似乎在抱怨.then 行,我不知道为什么。

$scope.showNewTeamDialog = function (ev) {
        $mdDialog.show({
            controller: NewTeamDialogController,
            templateUrl: 'NewTeam.html',
            locals: { newTeamName: $scope.newTeamName },
            parent: angular.element(document.body),
            targetEvent: ev
        }).then((newTeamName) => {
            if (newTeamName != undefined) {
                $scope.newTeamName = newTeamName.newTeamName;
                $scope.createNewTeam();
            }
        });

    };

【问题讨论】:

  • 错误是什么?
  • IE 不支持箭头功能。

标签: javascript angularjs


【解决方案1】:

您必须修改您的代码以支持 IE。

$scope.showNewTeamDialog = function (ev) {
        $mdDialog.show({
            controller: NewTeamDialogController,
            templateUrl: 'NewTeam.html',
            locals: { newTeamName: $scope.newTeamName },
            parent: angular.element(document.body),
            targetEvent: ev
        }).then(function(newTeamName){
            if (newTeamName != undefined) {
                $scope.newTeamName = newTeamName.newTeamName;
                $scope.createNewTeam();
            }
        }.bind(this);
    };

IE 不支持您编写的语法。使用函数语法而不是箭头语法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-12
    • 2023-03-08
    • 1970-01-01
    • 2016-05-19
    相关资源
    最近更新 更多