Assume that I have two input boxes with corresponding ng-model as fname and lname. If I call http request as :
$http({method:'GET', url:'/search', params:{fname: fname, lname: lname}})
will it call to the url :
/search?fname=fname&lname=lname
The error I am getting at the backend(python) is :
cannot concatenate str and nontype objects.
Are these parameters not sent as strings? If not, how to get around with this?
Build URL
'/search'
as string. LikeActually I didn't use
but I'm sure "params" should be
JSON.stringify
like forPOST
After:
Here is a simple mathed to pass values from a route provider
Here is how you do it:
Angular takes care of encoding the parameters.
Maxim Shoustin's answer does not work (
{method:'GET', url:'/search', jsonData}
is not a valid JavaScript literal) and JeyTheva's answer, although simple, is dangerous as it allows XSS (unsafe values are not escaped when you concatenate them).We can use input data to pass it as a parameter in the HTML file w use ng-model to bind the value of input field.
and in the js file w use $scope to access this data:
Controller function will be something like that: