AngularJs ReferenceError: $http 未定义 [英] AngularJs ReferenceError: $http is not defined

查看:31
本文介绍了AngularJs ReferenceError: $http 未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 Angular 函数:

I have the following Angular function:

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

但是每当调用此函数时,我都会在控制台中收到 ReferenceError: $http is not defined.有人可以帮助我理解我在这里做错了什么吗?

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?

推荐答案

可能你还没有将 $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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆