1

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?

3
  • 1
    It will be undefined in first call. Commented Feb 16, 2015 at 10:56
  • 1
    $scope.addVote must be their in your controller and addVote(key) is the correct syntax. Commented Feb 16, 2015 at 10:59
  • i want to do like this for couple of variables $scope.clearText = function(test){ $scope.test = ' ' ;} Commented Jan 15, 2017 at 15:30

2 Answers 2

2

Remove {{}} and send simple object

ng-click="addVote(key)"
Sign up to request clarification or add additional context in comments.

1 Comment

is there any way to get the reference of that variable in the controller method ?
1

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.