AngularJS$http未定义
I getAngularJS$http未定义,http,angularjs,module,Http,Angularjs,Module,I getTypeError:运行此模块时无法调用未定义的方法“get”: angular.module('EventList', []) .config([ '$routeProvider', function config($routeProvider){ $routeProvider.when(Urls.EVENT_LIST_PAGE, { templateUrl: 'app/EventList/event-list.html', controll
TypeError:运行此模块时无法调用未定义的方法“get”:
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";
}
);
}]);
angular.module('EventList',[])
.config(['$routeProvider',函数配置($routeProvider){
$routeProvider.when(url.EVENT\u LIST\u页面{
templateUrl:'app/EventList/event list.html',
控制器:“EventListCtrl”
});
}])
.controller('EventListCtrl',['$scope','$http',函数EventListController($scope,$location,$http){
$scope.events=[];
$http.get('http://localhost:8000/event').
成功(功能(数据、状态){
$scope.events=数据;
对于(变量i=0;i<$scope.events.length;i++){
$scope.events[i].event_url=('#'+url.event_PAGE+'/'+$scope.events[i].\u id);
}
}).
错误(功能(数据、状态){
$scope.data=data | |“请求失败”;
}
);
}]);
我在这里做错了什么?如何修复它?在函数需要匹配注入到函数中的服务之前,使用括号表示依赖项列表
您的EventsListController
功能中有一个额外的$location
服务,因此请更改此项:
.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
}]);
关键的变化是:function EventListController($scope,$http)
而不是function EventListController($scope,$location,$http)
我希望我能对这个答案投两次赞成票!这不是我的确切原因,但有帮助。我的编辑器无法更新我的.min文件,该文件仅用于生产环境,因此我花了相当长的时间试图找出我的部署破坏了生产环境而没有破坏其他环境的原因。谢谢你救了我的周末!