6

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?

2
  • 2
    try this <a ng-click="switchLanguage(language.value)" >Translate</a> Commented Mar 8, 2016 at 6:40
  • for those interested in angular (not js), the syntax is (click)="switchLanguage(lang.value)" Commented Jul 16, 2019 at 9:46

3 Answers 3

7

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

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

Sign up to request clarification or add additional context in comments.

Comments

4

Instead of

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

Use this

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

Comments

3

You can pass the value in this way :

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

This <a ng-click="switchLanguage('{{language.value}}')" >Translate</a> will pass the '{{language.value}}' as a value.

1 Comment

how can we pass like this <a (click)="language.value">Translate</a> language.value is dynamic is it possible?

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.