Tuesday, May 14, 2024
 Popular · Latest · Hot · Upcoming
88
rated 0 times [  90] [ 2]  / answers: 1 / hits: 162465  / 12 Years ago, fri, december 7, 2012, 12:00:00

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?


More From » angularjs

 Answers
19

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
}

[#81558] Thursday, December 6, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryanulyssesb

Total Points: 91
Total Questions: 105
Total Answers: 102

Location: England
Member since Tue, Sep 8, 2020
4 Years ago
;