AngularJS: html special characters are not displayed

I am trying to show a string in my model that contains an html representation of a special character. Unfortunately, he does not show this factual nature, and I do not know how to get him to do this ...

this is the code:

<div ng-controller="MyCtrl"> Hello, {{namea}}! <br/> &lt; </div> <script> var myApp = angular.module('myApp',[]); function MyCtrl($scope) { $scope.namea = 'Superhero &lt;'; } </script> 

this is the result:

 Hello, Superhero &lt;! < 

here for this jsfiddle

+7
source share
2 answers

You can use the ng-bind-html-unsafe directive :

 <div ng-controller="MyCtrl" ng-bind-html-unsafe="'Hello,' + namea"> </div> 

Check out the examples in the docs and jsfiddle .

+6
source

Today I ran into this problem. Using AngularJS, in the data inside the controller, I tried to include a string with "n" with a tilde. I tried "Español" as well as the html view, and did not display the desired result.

The employee said that Unicode is working. So I tried

 { name : "my site en Espan\u00F1ol" } 

who gave me

 my site en Español 

optional. Check out http://unicode-table.com/en/

+16
source

All Articles