2016-11-07 135 views
1

我討厭問這個問題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錯誤。我的代碼結構如下:錯誤:[ng:areq]參數'MainController'不是一個函數,在IE中未定義

的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中發生的事實提供了一個關於我的問題的提示?

回答

2

我覺得你的問題是默認PARAMS:

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

這是一個ES6 feature,並根據此compatability chart,IE11和邊緣只對ES6部分支持。直到Edge 14才支持它。

您可以更改代碼,使用轉譯器,使用ES6 shim或(Internet Explorer)的(我最喜歡的)刪除支持。

+0

謝謝,這解決了這個問題!我認爲有一個兼容性問題的地方,但哇...默認參數只是覺得很正常我不認爲這將是原因。不幸的是,我需要測試這個項目回到IE9 ... – btathalon

相關問題