Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I have the following angular function

$scope.updateStatus = function(user){    
 $http({
  url: user.update_path, 
  method: "POST",
  data: {user_id: user.id, draft: true}
 });
};

But whenever this function is called, I am getting the ReferenceError: $http is not defined in my console. Can anyone help me understand what i am doing wrong here.

share|improve this question

2 Answers 2

up vote 263 down vote accepted

Probably you haven't injected $http service to your controller. There are several ways of doing that.

Please read this reference about DI. Then it gets very simple:

function MyController($scope, $http) {
   // ... your code
}
share|improve this answer
13  
Thanks! I wonder why Angular's own documentation (docs.angularjs.org/tutorial/step_05) has this error. – Anurag Oct 9 '13 at 11:49
3  
I love stackoverflow, I just type a problem in google an imidiatelly there is always somebody, knowing somehow ( ;> ) how to solve it, without digging it out from documentation. – friko Jul 15 at 20:44

I have gone through the same problem when I was using

    myApp.controller('mainController', ['$scope', function($scope,) {
        //$http was not working in this
    }]);

I have changed the above code to given below. Remember to include $http(2 times) as given below.

 myApp.controller('mainController', ['$scope','$http', function($scope,$http) {
      //$http is working in this
 }]);

and It has worked well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.