Andrey Over
Andrey Over

Reputation: 21

Special characters in angularJs function parameter

I'm trying to call function with parameter that contains html tags and special characters:

$scope.translate is JSON like {"phrase": "phrase1"}

JS:

   $scope.t = function(phrase) {
    if ($scope.translate[phrase]) {
      return $scope.translate[phrase];
    } else {
      return phrase;
    }
   }

HTML:

<label class="sub-label" for="" >{{t("Fields required are marked with <span> * </ span>")}}</label>

When there are special characters - the function is not processed, but instead shows the code. I guess that this is the result of processing variables in angularJS. How do I properly solve this problem?

Upvotes: 0

Views: 1049

Answers (2)

tom
tom

Reputation: 692

If you have this hardcoded in your HTML template, you will need to put entities for special characters. This means using

<label class="sub-label" for="" >{{t("Fields required are marked with &lt;span&gt; * &lt;/ span&gt;")}}</label>

instead.

Upvotes: 1

ngDeveloper
ngDeveloper

Reputation: 1304

Might have to include ngSanitize package in your app, and then use ngBindHtml directive.

Upvotes: 0

Related Questions