Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-html-bind omitting style tag

Tags:

angularjs

I have an ng-bind like this

<p ng-bind-html="decodeText(item.description)"></p>

with decodeText

$scope.decodeText = function (data) {
    return data
}

however, the following json loses the style attribute style="color:#ff0000;" when rendered

[{"title":"I am here","date_received":"Feb 28, 2014","description":"<p>EE)\u00a0 <span style=\"color:#ff0000;\"> accepted<\/span><\/p>\n<p>HH)\u00a0 <span style=\"color:#ff0000;\">I am\nhere; <\/span><strong>\u00a0<\/strong><\/p>"}

what's causing this?

like image 898
Gollum Stripes Avatar asked Oct 02 '22 09:10

Gollum Stripes


1 Answers

ng-bind-html and $sce.trustAsHtml are always used together for displaying flat HTML.

It seems you are missing the $sce part in your code.

Try this instead:

$scope.decodeText = function (data) {
    return $sce.trustAsHtml(data);
}
like image 123
Davin Tryon Avatar answered Oct 05 '22 10:10

Davin Tryon