Base solution for your next web application
Open Closed

How to localize strings in the ng-options/Angular directive #457


User avatar
0
sylfree9999 created

Hi,

What I would like to achieve is that I want to have a localized label for <option> elements while the <option> are populated by the ng-options directive.

I know I can populate the <option> like this:

<select class="M_Select" ng-model="currentContact.roleRelationship" ng-options="t.number as t.value for t in roleRelationships"> </select>

and in the above code, 't.value' is used as the label for the <option> label. Is it possible to write code like this:

<select class="M_Select" ng-model="currentContact.roleRelationship" ng-options="t.number as @L("t.value") for t in roleRelationships"> </select>

But obviously, this would not work. So is it possible to localize strings inside the angularJs directives? If it can, how can I achieve this?

And what is the sequence for the rendering, I mean, if I wrote something like this, the {{}} seems not getting the correct value ready before calling L method.

@L({{currentContact.roleRelationship}})

Some help would be much appreciated! Thanks in advance!


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Angular views is rendered in client side. @L is a Razor view method and it's run on server side. So, your code can not work.

    ABP has a client-side localization API (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Localization#DocInJavascript">http://www.aspnetboilerplate.com/Pages/ ... Javascript</a>). So, you can add a function to your angular controller, like vm.localize = function(name) {...} (and use ABP localization api inside) and use it from your angular view.