错误:[ng:areq] Argument' MainController'不是一个函数,在IE中未定义

时间:2016-11-07 19:42:26

标签: javascript angularjs

我讨厌问这个问题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) {
        ....
    });

MapService.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中的事实是否提供了关于我的问题的提示?

1 个答案:

答案 0 :(得分:3)

我认为你的问题是默认的参数:

ind=$scope.currentId, prev=$scope.prevId
...
isVisible=false, counter=1

这是ES6 feature,根据此compatability chart,IE11和Edge仅部分支持ES6。直到Edge 14才支持它。

您可以更改代码,使用转换器,使用ES6 shim或(我最喜欢的)支持Internet Explorer。