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 ReferenceError: $http is not defined
in my console. Can someone help me understanding what I am doing wrong here?
Just to complete Amit Garg answer, there are several ways to inject dependencies in AngularJS.
You can also use
$inject
to add a dependency:I have gone through the same problem when I was using
I have changed the above code to given below. Remember to include $http(2 times) as given below.
and It has worked well.
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: