Display style tag in angular js while translation

547 views Asked by At

This is my controller file wherein

$scope.htmlCompanyFromScope = '<span style=color:red>Micro</span>';
$scope.htmlTagFromScope = "MicroTag";

My *.resx file contains

 TranslationValue = "{{htmlCompany}} tag is {{htmlTag}}"

And in my HTML I define the following:

 <span translate="TranslationValue " translate-values="{htmlCompany: htmlCompanyFromScope , htmlTag: htmlTagFromScope}"></span>

But in the end, the style is not honored. Displays something like

Micro tag is MicroTag

any pointers ?

2

There are 2 answers

1
Stanislav Kvitash On BEST ANSWER

I assume you are using sanitize strategy for escaping like:

$translateProvider.useSanitizeValueStrategy('sanitize');

It uses $sanitize service, so style attributes will get stripped by this service (and to overwrite this you'll need to change the source code of angular-sanitize.js, but I don't recommend doing this). As a workaround here - you need to use class attributes (since class attributes are not stripped with $sanitize) like class="red" and set proper css styles like .red { color:red; }.

Example here.

0
Jeremy Thille On

Use

<span style="color:red">

not

<span style=color:red>