$http() 不是一个函数
$http() is not a function
Enter Where Condition: <input type="text" id="myText">
<button onclick="myFunction()">Go</button>
<script type="text/javascript">
function myFunction($http) {
var condition = document.getElementById("myText").value;
$http({
method: 'POST',
url: "http://localhost:8080/peter/peter1/where",
params: {"where":condition},
headers: {'Content-Type': 'application/json'}
});
}
<script/>
当我尝试调试上面的代码时,我收到一个错误,说 $http不是一个函数...在上面的代码中,我收到错误 说$http不是一个函数。请帮助我解决这个问题...
$http是使用AngularJS时可以注入的服务。
您现在在代码中拥有的内容将不起作用,因为您定义了一个函数,该函数需要一个名为 $http
的参数,您尚未传递该参数。
最重要的是,它期望$http
参数是一个接受对象(大概是为了将数据发布到服务器)的函数。
下面是如何在 Angular 中执行您尝试执行的操作的示例。
这是我非常喜欢 egghead.io 的角度教程
Enter Where Condition: <input type="text" id="myText">
<button onclick="myFunction($my_http)">Go</button>
<script type="text/javascript">
function myFunction($http) {
var condition = document.getElementById("myText").value;
$http({
method: 'POST',
url: "http://localhost:8080/peter/peter1/where",
params: {"where":condition},
headers: {'Content-Type': 'application/json'}
});
}
<script/>
请注意,当您调用函数 myFunction() 时,应该使用包含 $http 对象的参数调用它,如下所示:
myFunction($http_example);
而不是这样:
myFunction();
相关文章:
- 我可以在json对象中添加一个函数吗
- 如何在JQuery函数中定义一个值,然后调用另一个函数并使用该值
- 是否可以将一个函数输入连接到另一个函数调用的文本
- 在另一个函数中使用变量this
- 在另一个函数成功结束后调用该函数
- mongoose.connect undefined不是一个函数
- 监听器必须是一个函数
- 使用JS函数来使用另一个函数的语法?node.js
- 如何取消object.prototypes javascript的一个函数
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 嵌套到另一个函数中的Fancybox函数;不起作用
- 如何在javascript中使用不止一个函数
- jQuery-在页面加载时执行一个函数
- jquery UI draggable:UI.children不是一个函数
- jQuery Mobile Undefined不是一个函数
- 如何在php中创建一个函数,该函数与文本区域一起工作,通过输入类似[color:red]的内容来打印具有等效颜色的文本
- javascript函数将数据添加到屏幕,但随后被另一个函数覆盖
- JS异常:animate不是一个函数
- 如何将一个函数附加到一个不存在的元素上
- JavaScript/jQuery-添加添加和删除类与下一个函数之间的延迟