AngularJs ReferenceError:$ http没有定义
我有以下的Angular函数:
$scope.updateStatus = function(user) { $http({ url: user.update_path, method: "POST", data: {user_id: user.id, draft: true} }); };  但是,每当这个函数被调用,我得到ReferenceError: $http is not defined在我的控制台中ReferenceError: $http is not defined 。 有人能帮我理解我在这里做错了吗? 
 可能你没有注入$http服务到你的控制器。 有几种方法可以做到这一点。 
请阅读关于DI的参考 。 然后它变得非常简单:
 function MyController($scope, $http) { // ... your code } 
我在使用时遇到了同样的问题
  myApp.controller('mainController', ['$scope', function($scope,) { //$http was not working in this }]); 
我已经改变了上面的代码给下面。 请记住包含下面给出的$ http(2次)。
  myApp.controller('mainController', ['$scope','$http', function($scope,$http) { //$http is working in this }]); 
它运作良好。
为了完成Amit Garg的回答 ,有几种方法在AngularJS中注入依赖关系。
 您也可以使用$inject来添加依赖项: 
 var MyController = function($scope, $http) { // ... } MyController.$inject = ['$scope', '$http'];