1

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?

2 Answers 2

3

Don't use interpolation ({{}}) inside ng-click directive.

ng-click = "urlSetter(item.url)"
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.