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/>
When i tried to debug the above code i am getting an error saying that $http is not a function... In the above code i am getting error saying $http is not a function..please help me in resolving this problem...
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/>
Notice that when you are calling the function myFunction() it should be called with a parameter containing an $http Object, like so:
myFunction($http_example);
AND NOT like so:
myFunction();
$http is a service you can inject when using AngularJS.
What you have in your code right now won't work because you defined a function which expects an argument called $http
, which you haven't passed.
On top of this it expects that $http
argument is a function that accepts an object presumably to post data to a server.
Here is an example of how to do what you are trying to do in Angular.
Here is an Angular Tutorial by egghead.io which I quite like