I've called a function on the ng-click
event from my html but would like to pass the output of an ng-repeat
as a parameter to that function. INthis case {{item.url}}
is the output of the ng-repeat
.
ng-click = "urlSetter({{item.url}})"
Within the Controller
of the page I have created the relevent function and set it in the $scope
.
$scope.urlSetter = function(url){
console.log(url);
};
How can I pass the binding to the function?
不要在ng-click
指令中使用插值( {{}}
)。
ng-click = "urlSetter(item.url)"
Assuming you are iterating through the list of items
here is how you do it.
<div ng-repeat="item in items" ng-click="urlSetter(item.url)"></div>
The usage {{item.url}}
is used inside the HTML elements to output the bound valueof item.url
onto the HTML. But when you pass it to a controller method you can just use the variable name
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.