1

Is it possible to make a "double data-binding" with angularJS ?

I want to get mat.Discipline[0].nom_FR in an array that have nom_FR, nom_DE, nom_EN and nom_IT.

mat.Langue[0].langue give me "FR", "DE", "EN" or "IT" depending what language the user choose.

So I would like to use {{mat.Langue[0].langue}} to determine if the discipline should be nom_FR, nom_DE or another...

I try to do something like that: {{mat.Discipline[0].nom_{{mat.Langue[0].langue}}}} but of course, it doesn't work...

Do you have an idea ? Thanks a lot!

Jaqen H'ghar
17k8 gold badges52 silver badges53 bronze badges
asked Aug 6, 2016 at 10:42

2 Answers 2

1

Use square brackets notation:

{{mat.Discipline[0]["nom_" + mat.Langue[0].langue]}};
answered Aug 6, 2016 at 10:55
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer! Saddly, it doesn't work... I don't have an error, but nothing appears in the HTML, like if he found nothing...
@Nooka10 well it probably solved the original problem but there's another one :) If you want post a jsfiddle I'll take a look
0

Thanks a lot, it finally work! ^^

I use your answer, but in javascript and it work!

Here is what I do in my Javascript:

for (var i = 0; i < vm.allMateriel.length; i ++) {
 var langue = vm.allMateriel[i].Langue[0].langue;
 vm.allMateriel[i].Discipline[0].nom = vm.allMateriel[i].Discipline[0]['nom_' + langue];
}
answered Aug 6, 2016 at 12:00

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.