2

Hi guys I'm looking for a way to use variable in angularJS expression. Something like this :

{{locale['static text' + variable]}}

I've tried many ways include escape the quote, but it doesn't to work.

For more information:

locale is $rootScope.locale where I put the locale content depending language.

variable is $scope.variable

5
  • 1
    Ok - so, locale is an array and you are attempting to read a particular entry in this array using the index present in variable? Commented May 27, 2013 at 8:38
  • @callmekatootie yes, exactly :) Commented May 27, 2013 at 9:14
  • 1
    Doesn't @Aleksander's solution below work for you? Commented May 27, 2013 at 10:18
  • it works but what I want more is to inject some static text like in the question. Commented May 27, 2013 at 10:34
  • @vdt I've updated my plunkr, also with static text. Commented May 27, 2013 at 10:48

2 Answers 2

2

{{locale['static text' + variable]}} works fine. See this Plunker for a full example:

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

Comments

0

I think you are looking for http://docs.angularjs.org/api/ng.directive:ngBindHtmlUnsafe.

ng-bind-html-unsafe will make the expression unquoted, that's why it is kind of unsafe. A reminder, when working with ng directives, do not surround the expression with "{{}}".

Comments

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.