Angular: Binding an HTML value

Posted . Visible to the public.

To bind an HTML value to ng-bind-html, you need to mark it as "trusted" first. Among other ways, you can do so with a custom filter.

# Filter in Coffeescript...:
@app.filter 'htmlSafe', ['$sce', ($sce) -> $sce.trustAsHtml ]

# ...or JS:
app.filter('htmlSafe', [
  '$sce', function($sce) {
    return $sce.trustAsHtml;
  }
]);

# Usage:
<div ng-bind-html="item.value | htmlSafe"></div>

This is a replacement for the ng-bind-html-unsafe directive which has been removed in Angular 1.2.

:party:

Last edit
Deleted user #3651
License
Source code in this card is licensed under the MIT License.
Posted to makandra dev (2014-11-13 18:04)