Skip to content

Instantly share code, notes, and snippets.

@leon
Created August 30, 2013 09:50
Show Gist options
  • Save leon/6388221 to your computer and use it in GitHub Desktop.
Save leon/6388221 to your computer and use it in GitHub Desktop.
Angular 1.2 workaround for ng-bind-html-unsafe
'use strict';
angular.module('app').directive('ngBindHtmlUnsafe', function ($sce) {
return {
constrain: 'E',
link: function (scope, element, attr) {
scope.$watch($sce.parseAsHtml(attr.ngBindHtmlUnsafe), function(value) {
element.html(value || '');
});
}
};
});
@tschofen
Copy link

No matter what I do, I end up with no content. Any idea what I'm doing wrong?

I tried many variations:

<div class="content" ng-bind-html-unsafe="content.description"></div>
<div class="content" ng-bind-html-unsafe="'content.description'"></div>
<div class="content" ng-bind-html-unsafe>{{content.description}}</div>
<div class="content" ng-bind-html-unsafe="content.description">{{content.description}}</div>
<ng-bind-html-unsafe="content.description"></ng-bind-html-unsafe>
<ng-bind-html-unsafe>{{content.description}}</ng-bind-html-unsafe>
<ng-bind-html-unsafe="content.description">{{content.description}}</ng-bind-html-unsafe>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment