Javascript – Pass a dynamic value to a function in angular with ng-click

angularjsangularjs-ng-clickjavascript

I'm trying to use a link to dynamically translate a website.

This is my HTML:

<a  ng-click="switchLanguage('{{language.value}}')" >Translate</a>

{{language.value}} is a dynamic value taken from a json file and I can verify that upon runtime, it does get populated with the proper value ('en-us','ja-jp', etc…)

And here's my function inside a controller:

function switchLanguage(newlan) {
    console.log(newlan);
}

However, everytime I click on the link, the console shows the value as {{language.value}}, instead of the proper value (ex: en-us).

How do I make the value inside the ng-click pass the correct parameter to the function?

Best Answer

use ng-click="switchLanguage(language.value)"

Here is the PLUNKER: http://plnkr.co/edit/uOUD9f1P3tKp3IlGsjBK?p=preview