角度控制器仅在Mozilla Firefox上未定义

时间:2015-12-24 10:38:42

标签: javascript angularjs firefox iife

我无法理解为什么以下内容仅适用于Firefox (它在Google Chrome和IE11上完美运行):

index.js:

  when("/d2d/", {
    templateUrl: "modules/d2d/d2d.view.html",
    controller: "D2DCtrl",
    controllerAs: "vm"
  }).

控制器:

(function() {

  "use strict";

  angular
    .module("app.d2d")
    .controller("D2DCtrl", D2DCtrl);

  D2DCtrl.$inject = ["$scope", "$log", "myService"];

  function D2DCtrl($scope, $log, myService) {
      var vm = this;
      ...

  }
})();

控制器

我在视图开启时遇到此错误:

Error: [ng:areq] http://errors.angularjs.org/1.4.8/ng/areq?p0=D2DCtrl&p1=not%20a1,#QNAN0unction%2C%20got%20undefined

有什么想法吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

我终于找到了这个问题。我会在这里发布,因为它可以帮助其他人。

问题的根源是在控制器内部使用ES6“let”关键字,如果没有这个关键字,则无法在Mozilla Firefox 43中使用:

<script type="application/javascript;version=1.7" src="app.js"></script>

编辑:添加此元素,它在Google Chrome上不再有效......

相关问题