Lee Lee
Lee Lee

Reputation: 583

how to pass parameter from view to controller in angularjs

In my controller I have this function:

$scope.add = function(key){
   $scope.key = key;
};

And this is my html view:

 <button type="button" ng-click="addVote({{key}});">Confirm</button>

My question is about the ng-click="addVote({{key}}). I want to call the $scope.key value in my view. It doesn't work. What the mistake I did?

Upvotes: 1

Views: 2006

Answers (2)

thedoctor
thedoctor

Reputation: 1508

You don't need to perform any interpolation in attributes such as ng-click. So your code should be as follows:

<button type="button" ng-click="addVote(key);">Confirm</button>

Upvotes: 1

squiroid
squiroid

Reputation: 14027

Remove {{}} and send simple object

ng-click="addVote(key)"

Upvotes: 2

Related Questions