Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS Injector Error Uncaught Error: [$injector:modulerr]

I am new to AngularJS and I am trying to follow some structure for scalable applications, as well as trying to get Firebase working. However, I am getting a simple error on the injector. When I view the error tree, it seems to be all AngularJS references, and I do not see a reference to an object in my code. I guess I am looking in the wrong place?

Failed to instantiate module MyApp due to:
Error: [$injector:unpr] http://errors.angularjs.org/1.3.11/$injector/unpr?p0=e
    at Error (native)
    at     https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:6:417
    at      https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:38:307
    at d     (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:36:308)
    at Object.e [as invoke]     (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:37:64)
    at d     (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:35:301)
    at     https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:35:425
    at s     (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:7:302)
    at g     (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:35:202)
    at Ob     (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js:38:435

This is my Plunkr sample

like image 235
Steven Scott Avatar asked Mar 08 '26 16:03

Steven Scott


1 Answers

It seems you don't get $scope right.

For routeProvider, it's templateUrl instead of templateURL. For TeamCtrl, if you want to bind a object to View, remember to add this object to $scope.

angular.module('MyApp').config(function($routeProvider) {
    $routeProvider
    .when('/', {
        controller: 'TeamCtrl',
        templateUrl: 'team.html'
    })
    .otherwise({
        redirectTo: '/'
    });

});

angular.module('MyApp').controller('TeamCtrl', ['$scope', '$firebase', 'Teams', 
    function ($scope, $firebase, Teams) {

        $scope.Teams = Teams;
        $scope.team = {};

        $scope.SaveTeam = function(team) {
            $scope.Teams.$add({
                Id: $scope.team.id,
                Name: $scope.team.Name,
                Wins: $scope.team.Wins,
                Losses: $scope.team.Losses
            });
        };

        $scope.team.id = "";
        $scope.team.Name = "";
        $scope.team.Wins = "";
        $scope.team.Losses = "";
    }
]);

For team.html

<div ng-repeat="team in Teams">
    <h2>{{team.Name}}</h2>
    {{team.Wins}} / {{team.Losses}}
</div>
like image 117
Rebornix Avatar answered Mar 10 '26 12:03

Rebornix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!