Aitor Aitor - 5 months ago 103
AngularJS Question

Concatenate string on repeater with Angular Translate

I want to concatenate a string on a repeater using Angular Translate inside "small" tag to put a description. What i must do?

<li ng-repeat="subtype in type">
<label>
<input type="radio" name="radioType" ng-value="subtype" ng-model="dialogModel.type">
{{ subtype.name }} <small>{{ 'subtype.name + "_DESCRIPTION"' | translate }}</small>
</label>
</li>


Now it shows me a literal string, I don't know how concatenate an Angular Translate string.

Answer

If subtype.name + "_DESCRIPTION is the string you want to translate on, the outter ' is not needed.

{{ subtype.name }} <small>{{ (subtype.name + "_DESCRIPTION") | translate }}</small>

btw, if you have many many subtype to repeat, the translate may cause a performance problem , so try to use $filter('translate') in ctrl or simply use one-time binding with "::", it seems that you need not to update the _DESCRIPTION again after it rendered in your case.

{{ subtype.name }} <small>{{ ::(subtype.name + "_DESCRIPTION") | translate }}</small>