Display Unicode in HTML with AngularJS?
Avoid writing HTML markup from script. As soon as the data may content HTML-special characters like <
and &
you've got breakage and potentially security issues (XSS).
The character referred to by the HTML markup ↓
is U+2193 Downwards Arrow. You can refer to it directly in JavaScript using a JS string literal escape:
'name': '\u2193NASDAQ',
Or if your page/script is consistently saved and served in a Unicode-safe format (eg UTF-8) then you don't need to escape it at all:
'name': '↓NASDAQ',
Angular ships with Strict Contextual Escaping. So you'd have to explicitly say that you want to render some character as HTML.
Notice, I have also added ng-sanitize
in the External Resources.
I created a new filter
mOverview.filter('unsafe', function($sce) {
return function(val) {
return $sce.trustAsHtml(val);
};
});
and used it in view like this:
<td ng-bind-html="md.name | unsafe"></td>
http://jsfiddle.net/9UdVY/