How to resolve AnguarJS $injector:modulerr (detail

2019-09-02 16:24发布

I've been having trouble using custom directives for my web app. When I pull up the JS console in Chrome, I get this Failed to instantiate module w2l-direc due to: {1}. It seems that there's something wrong with the code I wrote in my module. I'm relatively new to angular so any feed back in regards to the following code would be appreciated

(function() {
var app = angular.module('w2l-directives', ['ui.bootstrap', 'ngRoute']);
app.directive('gamesCol',['$http', function($http){
        return {
            restrict: 'E',
            templateUrl: 'games-col.html',
            controller: function(){
                this.games = $http.get('/js/games.json').success(function(data) {
                    this.games = data;
                });

                this.isSet = function(checkGame){
                    return this.game === checkGame;
                };

                this.setGame = function(activeGame){
                    this.game = activeGame;
                };
            },
            controllerAs:'game'
        };
    }]);

    app.directive('testimonyCol', function(){
        return {
            restrict: 'E',
            templateUrl: 'testimonies-col.html',
            controller: function(){
                this.testimonials = $http.get('/js/testimonies.json').successs(function(data) {
                    this.testimonials = data;
                }); 
                this.current = 0
                this.currentTestimony = testimonies[current];

                this.setTestimony = function(checked){
                    if (checked !== this.currentTestimony) {
                    this.current = checked || 0;
                    }
                };
            },
            controllerAs:'testimony'
        };
    });
})();`

2条回答
Viruses.
2楼-- · 2019-09-02 16:51

Your error message looks weird to me, it should have included a reason in stead of {1}.

Anyway, what comes to mind, is that angular can't find your module dependencies. Can you check that ui.route's script file is included on the page?

ui.bootstrap is not part of the angular distro. You can find it here: http://angular-ui.github.io/bootstrap/. (Or simply remove the dependency, if you are not using it)

查看更多
Luminary・发光体
3楼-- · 2019-09-02 16:52

Just a hint: try to check your code in Firefox console, it gives you more detail information about your problem than chrome.

查看更多
登录 后发表回答