Tzu ng
Tzu ng

Reputation: 9234

Variable in angularjs expression

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

Upvotes: 2

Views: 2525

Answers (2)

Z.T. Yang
Z.T. Yang

Reputation: 342

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 "{{}}".

Upvotes: 0

Aleksander Blomskøld
Aleksander Blomskøld

Reputation: 18542

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

Upvotes: 2

Related Questions