Read more

Angular: Binding an HTML value

Thomas Klemm
November 13, 2014Software engineer

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>
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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

:party:

Posted by Thomas Klemm to makandra dev (2014-11-13 19:04)