2013-07-07 3 views
9

I 얻을 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

대괄호 표기법을 사용하면 함수 앞에 종속 목록이 함수에 삽입되는 서비스와 일치해야합니다. 내가 소원 function EventListController($scope, $http) 대신 function EventListController($scope, $location, $http)

+0

의 :

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

주요 변경 존재 : 이것에

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

:

당신은 그래서 이것을 변경하려면 EventsListController 기능에 추가 $location 서비스를 이 답변을 두 번 upvote 수 있습니다! 이것은 정확한 원인은 아니지만 도움이되었습니다. 편집인이 프로덕션에서만 사용되는 .min 파일을 업데이트하지 못하여 배포가 생산 중단과 다른 환경을 뚫지 못하는 이유를 알아 내려고 노력했습니다. 주말을 보내 주셔서 감사합니다! –

관련 문제