Renaud is Not Bill Gates
Renaud is Not Bill Gates

Reputation: 2074

ng-click with a href in angularjs

And I have the following links in my page as following :

<li ng-repeat="o in villes | shuffle | limitTo:5"><a href="#" ng-click="searchByVille({{o.codeVille}})">{{o.nomVille}}</a></li>

I want when I click on some link to call the searchByVille function and to log the parameter I passed to it as following :

$scope.search = function(id){
    console.log(id);
  }

which doesn't work.

How can I solve this ?

Upvotes: 1

Views: 2066

Answers (2)

Prakash Mishra
Prakash Mishra

Reputation: 109

No need to evaluate using {{}}. Use data-ng-click="searchByVille(o.codeVille)"

Upvotes: 0

tymeJV
tymeJV

Reputation: 104775

Omit the {{}} in your ngClick directive:

ng-click="searchByVille(o.codeVille)"

ngClick already takes an Angular expression - no need for them.

Upvotes: 4

Related Questions