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 时注入(inject)的服务.
您现在的代码中的内容将不起作用,因为您定义了一个函数,该函数需要一个名为 $http
的参数,而您尚未传递该参数。
除此之外,它期望 $http
参数是一个函数,该函数接受一个可能将数据发布到服务器的对象。
这是一个example如何在 Angular 中完成您想要做的事情。
这是一个Angular Tutorial作者:egghead.io,我很喜欢
关于javascript - $http() 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34997154/