0

I have an angular directive which prints a title with key contained in a messages.properties file. I would like to dynamically generate the key by concatenate 'root.'+scope.value + '.title' like this

titre="{{ 'flux.' + 'typeFlux' + '.title' }}"

The result should be like titre="{{ 'flux.typeFlux.title' }}"

How can i do this in my html file?

Thanks.

3
  • 'root.' + value + '.title'? Commented Sep 14, 2017 at 16:22
  • The value of 'typeFlux' is in the scope and can change. Commented Sep 14, 2017 at 16:23
  • Yes, I understand that. Every variable you use in an angular expression is always evaluated as a scope attribute. Commented Sep 14, 2017 at 16:25

1 Answer 1

2

In this instance, you want to use Object Bracket Notation. The dynamic portion of the expression is used as an object property reference, like so:

{{flux[typeFlux].title}}

http://plnkr.co/edit/OHK7XqZyv2eKhrOROkqi?p=preview

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

3 Comments

Thanks for your answer. I will try it tomorrow
your sample doesn't work for multiple reasons. Firstly, you can't create an object the way you have tried (i.e. $scope.flux.webdyn.title = 'Title Webdyn'; won't work to create the nested properties). Secondly, there is no . between the object and the property in the HTML (i.e. it's flux[flux.typeflux].title in your example, not flux.[ ...
I forked your example to show it working: plnkr.co/edit/lBNVqx02jg3bDYTh4MHw?p=preview

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.