【发布时间】:2016-11-07 19:42:26
【问题描述】:
我讨厌问这个问题 b/c 有很多类似的问题,但我今天浪费了 5 个小时试图解决导致此问题的原因。我的应用在 Chrome 和 Firefox 中运行完美,但在 IE 11 或 Edge 中,我收到 SCRIPT1006: Expected ')' MapService.js (43,55)、SCRIPT1006: Expected ')' MainController.js (299,44) 和 Error: [ng:areq] Argument 'MainController' is not a function, got undefined 错误。我的代码结构如下:
index.html
<html lang="en" ng-app="SS" ng-controller="MainController as ctrl" >
<script src="src/index.js"></script>
<script src="src/SS/DefaultConfigs.js"></script>
<script src="src/SS/MapService.js"></script>
<script src="src/SS/MainController.js"></script>
....
index.js
angular
.module("SS", ["ngMaterial", "angular-intro"])
.config(function($mdThemingProvider, $mdIconProvider) {
"use strict";
$mdIconProvider
.defaultIconSet("./assets/svg/settings.svg", 128)
.icon("clipboard", "./assets/svg/clipboard_48px.svg", 48)
.icon("close", "./assets/svg/close_48px.svg", 48);
....
$mdThemingProvider.theme("default")
.primaryPalette("blue")
.dark();
});
MainController.js
angular
.module('SS')
.controller('MainController', function($interval, $location, $mdDialog, $mdSidenav, $mdToast, $scope, DefaultConfigs, MapService) {
'use strict';
var animationRunner;
....
/* Snippet of code surrounding where 2nd error supposedly is */
var updateMap = function() {
MapService.updateCurrentRotation();
MapService.updateCurrentZoom();
MapService.updateCurrentCenter();
$scope.setVisibility();
};
// line below is line 299
$scope.setVisibility = function(ind=$scope.currentId, prev=$scope.prevId) {
var temp = MapService.layers;
if (layerExists(prev)) {
temp[prev].setVisible(false);
}
if (layerExists(ind)) {
temp[ind].setVisible(true);
}
};
/* End snippet of code surrounding where 2nd error supposedly is */
})
.directive('ngRightClick', function($parse) {
....
});
地图服务.js
angular
.module('SS')
.service('MapService', function($location, DefaultConfigs) {
'use strict';
this.map = null;
this.layers = [];
/* Snippet of code surrounding where 1st error supposedly is */
this.createProjection = function() {
this.proj = new ol.proj.Projection({
code: 'EPSG:0000',
units: 'pixels',
extent: [0, 0, 8192, 8192]
});
};
/* next line is line 43 */
this.createLayer = function(ind, isVisible=false, counter=1) {
var imageLayer = new ol.layer.Tile({
preload: Infinity,
source: new ol.source.XYZ({
url: this.baseURL + ind + '/{z}-{y}-{x}.png',
projection: this.proj,
wrapX: false,
attributions: [this.tileAttribution]
}),
transitionEffect: 'resize',
visible: isVisible
});
imageLayer.id = counter;
imageLayer.playerId = parseInt(ind, 10);
return imageLayer;
};
/* End snippet of code surrounding where 1st error supposedly is */
});
我检查了 JSLint 以检查我的代码中的错误,但没有发现任何东西可以修复 IE 错误。我没有使用全局控制器声明,我没有调用 ng-app 两次,我相信我的 javascript 调用顺序正确,我没有覆盖我的 SS 模块,我没有发现任何逗号或括号错误。我难住了。我已经阅读了许多其他解决方案,并且检查了清单here 上的所有选项。
这两个) 错误一直显示并且仅在 IE 中发生的事实是否暗示了我的问题?
【问题讨论】:
标签: javascript angularjs