我的 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。
$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 不支持您编写的语法。使用函数语法而不是箭头语法。
关于javascript - 仅在 IE 浏览器中发生 Angular 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46322518/