2013-07-07 15 views
9

このモジュールを実行しているとき、私はTypeError: Cannot call method 'get' of undefinedを得る:私はここで間違って

angular.module('EventList', []) 

.config([ '$routeProvider', function config($routeProvider){ 
    $routeProvider.when(Urls.EVENT_LIST_PAGE, { 
     templateUrl: 'app/EventList/event-list.html', 
     controller: 'EventListCtrl' 
     }); 
}]) 


.controller('EventListCtrl', ['$scope', '$http', function EventListController($scope, $location, $http) { 
    $scope.events = []; 
    $http.get('http://localhost:8000/event'). 
    success(function (data, status) { 
     $scope.events = data; 
     for (var i = 0; i < $scope.events.length; i++) { 
     $scope.events[i].event_url = ('#' + Urls.EVENT_PAGE + '/' + $scope.events[i]._id); 
     } 
    }). 
    error(function (data, status) { 
     $scope.data = data || "Request failed"; 
    } 
); 

}]); 

何をやっているとどのように私はそれを修正することができますか?

答えて

18

ブラケット記法を使用する場合、関数の前に依存関係リストを挿入すると、関数に注入されるサービスが一致する必要があります。

あなたはので、この変更あなたのEventsListController機能に余分な$locationサービスを持っている:私は私が望むfunction EventListController($scope, $http)代わりのfunction EventListController($scope, $location, $http)

+0

:これまで

.controller('EventListCtrl', ['$scope', '$http', function EventListController($scope, $location, $http) { // controller code goes here }]); 

.controller('EventListCtrl', ['$scope', '$http', function EventListController($scope, $http) { // controller code goes here }]); 

キー変更ビーイングをこの回答を2回upvoteすることができます!これは私の正確な原因ではありませんでしたが、助けました。私のエディタは、プロダクションでのみ使用されている.minファイルの更新に失敗したので、なぜ私の配備が生産を壊したのか、それ以外の環境がないのかを理解しようとしました。私の週末を保存してくれてありがとう! –