javascript - $http() 不是一个函数

标签 javascript html angularjs ajax

 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/

相关文章:

javascript - 从两端调整一个div的大小

javascript - 保持日期选择器粘在文本字段上

javascript - 确定 Angular js中的对象已更改

angularjs - 如何处理 resolve : clause of $routeProvider 中的异常

php - 如何在一个php标签中定义的变量在另一个php标签中使用?

javascript - 当未通过单击按钮引用时,如何阻止对 URL 的直接访问?

javascript - 父 Div 元素内的图像居中问题

html - 在整页、变暗、模糊的背景图像上添加居中文本?

javascript - 势不可挡的addEventListener

javascript - AngularJS中的严格模式过滤器