Angularjs由于以下原因无法实例化模块WebApp:错误:在匿名函数

时间:2017-04-05 21:46:03

标签: javascript angularjs internet-explorer

我有一个angularjs应用程序,可以在Chrome和Firefox甚至Edge中完美运行!虽然不在IE11上。

我已尝试将init.js包装如下:

var webApp = angular.module('WebApp',['ngRoute','ui.bootstrap','angular-mandrill','firebase']);

(function() {

  angular.module('WebApp').run(function($rootScope,$timeout) {

         $timeout(function(){
                   $rootScope.$on('$routeChangeSuccess', function(ev, data) {
                    if (data && data.controller) {
                        var controller = data.controller;
                        controller = controller.charAt(0).toLowerCase() + controller.slice(1);
                        controller = controller.replace(/Controller/g, '');
                        $rootScope.controller = controller;
                    }
                });
        }, 100);


    }).$inject = ['$rootScope'];
}).bind(window);

我也试过包装我的所有控制器,如:

(function(angular){     “使用严格”;

//控制器在这里     }(window.angular));

其他人有什么想法吗? 谢谢!

EDITED! - 附加错误堆栈:) -

    HTML1300: Navigation occurred.
localhost:8000
SCRIPT1006: Expected ')'
angular-mandrill.js (1,597)
SCRIPT5022: [$injector:modulerr] http://errors.angularjs.org/1.5.5/$injector/modulerr?p0=WebApp&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.5.5%2F%24injector%2Fmodulerr%3Fp0%3Dangular-mandrill%26p1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.5.5%252F%2524injector%252Fnomod%253Fp0%253Dangular-mandrill%250A%2520%2520%2520at%2520Anonymous%2520function%2520(http%253A%252F%252Flocalhost%253A8000%252Fassets%252Fexternal%252Fangular%252Fangular.min.js%253A25%253A229)%250A%2520%2520%2520at%2520b%2520(http%253A%252F%252Flocalhost%253A8000%252Fassets%252Fexternal%252Fangular%252Fangular.min.js%253A24%253A263)%250A%2520%2520%2520at%2520Anonymous%2520function%2520(http%253A%252F%252Flocalhost%253A8000%252Fassets%252Fexternal%252Fangular%252Fangular.min.js%253A25%253A13)%250A%2520%2520%2520at%2520Anonymous%2520function%2520(http%253A%252F%252Flocalhost%253A8000%252Fassets%252Fexternal%252Fangular%252Fangular.min.js%253A39%253A372)%250A%2520%2520%2520at%2520q%2520(http%253A%252F%252Flocalhost%253A8000%252Fassets%252Fexternal%252Fangular%252Fangular.min.js%253A7%253A353)%250A%2520%2520%2520at%2520g%2520(http%253A%252F%252Flocalhost%253A8000%252Fassets%252Fexternal%252Fangular%252Fangular.min.js%253A39%253A222)%250A%2520%2520%2520at%2520Anonymous%2520function%2520(http%253A%252F%252Flocalhost%253A8000%252Fassets%252Fexternal%252Fangular%252Fangular.min.js%253A39%253A380)%250A%2520%2520%2520at%2520q%2520(http%253A%252F%252Flocalhost%253A8000%252Fassets%252Fexternal%252Fangular%252Fangular.min.js%253A7%253A353)%250A%2520%2520%2520at%2520g%2520(http%253A%252F%252Flocalhost%253A8000%252Fassets%252Fexternal%252Fangular%252Fangular.min.js%253A39%253A222)%250A%2520%2520%2520at%2520bb%2520(http%253A%252F%252Flocalhost%253A8000%252Fassets%252Fexternal%252Fangular%252Fangular.min.js%253A43%253A240)%0A%20%20%20at%20Anonymous%20function%20(http%3A%2F%2Flocalhost%3A8000%2Fassets%2Fexternal%2Fangular%2Fangular.min.js%3A40%3A25)%0A%20%20%20at%20q%20(http%3A%2F%2Flocalhost%3A8000%2Fassets%2Fexternal%2Fangular%2Fangular.min.js%3A7%3A353)%0A%20%20%20at%20g%20(http%3A%2F%2Flocalhost%3A8000%2Fassets%2Fexternal%2Fangular%2Fangular.min.js%3A39%3A222)%0A%20%20%20at%20Anonymous%20function%20(http%3A%2F%2Flocalhost%3A8000%2Fassets%2Fexternal%2Fangular%2Fangular.min.js%3A39%3A380)%0A%20%20%20at%20q%20(http%3A%2F%2Flocalhost%3A8000%2Fassets%2Fexternal%2Fangular%2Fangular.min.js%3A7%3A353)%0A%20%20%20at%20g%20(http%3A%2F%2Flocalhost%3A8000%2Fassets%2Fexternal%2Fangular%2Fangular.min.js%3A39%3A222)%0A%20%20%20at%20bb%20(http%3A%2F%2Flocalhost%3A8000%2Fassets%2Fexternal%2Fangular%2Fangular.min.js%3A43%3A240)%0A%20%20%20at%20c%20(http%3A%2F%2Flocalhost%3A8000%2Fassets%2Fexternal%2Fangular%2Fangular.min.js%3A21%3A17)%0A%20%20%20at%20yc%20(http%3A%2F%2Flocalhost%3A8000%2Fassets%2Fexternal%2Fangular%2Fangular.min.js%3A21%3A325)%0A%20%20%20at%20ee%20(http%3A%2F%2Flocalhost%3A8000%2Fassets%2Fexternal%2Fangular%2Fangular.min.js%3A20%3A156)
angular.min.js (40,25)
rendered http://localhost:8000/assets/css/style.less successfully.
css for http://localhost:8000/assets/css/style.less generated in 1641ms
less has finished. css generated in 1641ms

1 个答案:

答案 0 :(得分:1)

试试这个,它应该有效:

(function() {

  angular.module('WebApp', ['ngRoute', 'ui.bootstrap', 'angular-mandrill', 'firebase']);   

  angular.module('WebApp').run(['$rootScope', '$timeout', function($rootScope, $timeout) {

     $timeout(function() {
        $rootScope.$on('$routeChangeSuccess', function(ev, data) {
            if (data && data.controller) {
                var controller = data.controller;
                controller = controller.charAt(0).toLowerCase() + controller.slice(1);
                controller = controller.replace(/Controller/g, '');
                $rootScope.controller = controller;
            }
        });
    }, 100);

    }]);

})(); ;

错误堆栈显示模块' angular-mandrill'不可用。 确保在WebApp模块初始化之前加载它。

angular-mandrill.js添加到您的HTML中。

<script src="//rawgit.com/mrkvngrkn/angular-mandrill/master/dist/angular-mandrill.js"></script>

然后,添加angular-mandrill作为您应用的模块依赖项。 对ui.bootstrapfirebase

执行相同操作
angular.module('WebApp', ['angular-mandrill']);