Shesha Shesha - 6 months ago 14
Ajax Question

How to use template value while calling function?

HTML:

<li data-id="{{Name.first}}" ng-click="getNames('{{Name.first}}')">


Script:

$scope.getNames = function(name) { // I am getting "{{Name.first}}" which I sent. I am not getting the template value
$http({
method : "POST",
url : "/some/url",
params: { value: id },
headers: {
'Content-type': 'application/json'
}
}).then(function mySucces(response) {
$scope.Results = response.data;
});
}


Please tell me how to use template value while calling the method ?

Answer

Pass scope variable value without interpolation ({{}}) while calling function from ng-click directive.

<li data-id="{{Name.first}}" ng-click="getNames(Name.first)">