AngularJs的ReferenceError:$ HTTP是没有定义 [英] AngularJs ReferenceError: $http is not defined
本文介绍了AngularJs的ReferenceError:$ HTTP是没有定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的角功能
$scope.updateStatus = function(user){
$http({
url: user.update_path,
method: "POST",
data: {user_id: user.id, draft: true}
});
};
但每当这个函数被调用时,我收到的ReferenceError:$ HTTP是没有定义在我的控制台。谁能帮我明白我在做什么错在这里。
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.
推荐答案
也许你还没有注入 $ HTTP
服务到控制器。有这样做的几种方法。
Probably you haven't injected $http
service to your controller. There are several ways of doing that.
请阅读有关DI 此引用。然后,它变得很简单:
Please read this reference about DI. Then it gets very simple:
function MyController($scope, $http) {
// ... your code
}
这篇关于AngularJs的ReferenceError:$ HTTP是没有定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文