Search code examples
angularjsangular-translate

String with HTML tags - ng-translate


I'm working on an AngularJS Project and I have a JSON file with all my text in it. I have quite a chunk of text inside it with HTML tags like a break. The problem is when I want to display that text inside my html file it display as plain text like: 'this is text (breaktag<>) I want to use'.

This is the code I'm using to display the text inside my HTML file:

<p translate="requestGenerator.partnershipGenerationOverview.message"></p>

I am using ng-translate.

How can I solve this so that the translate directive uses the HTML tags instead of displaying it with plain text?


Solution

  • angular-translate provides a post compiling option, which you can either activate globally or for specific translations.

    Enable post compiling globally:

    app.config(function ($translateProvider) {
      $translateProvider.usePostCompiling(true);
    });
    

    Enable post compiling for just this translation:

    <p translate="requestGenerator.partnershipGenerationOverview.message"
       translate-compile>
    </p>