Skip to content

Instantly share code, notes, and snippets.

@dhigginbotham
Created October 23, 2014 14:18
Show Gist options
  • Save dhigginbotham/8aa05705a0dd0d92f69d to your computer and use it in GitHub Desktop.
Save dhigginbotham/8aa05705a0dd0d92f69d to your computer and use it in GitHub Desktop.
Angular likes to santize and escape all the things, this will help when you really need your api responses compiled as HTML
var app = app || {};
app.directive( 'compileHtml', ['$compile', '$sce',
function($compile, $sce) {
return {
scope: true,
link: function ( scope, element, attrs ) {
var el;
attrs.$observe( 'template', function ( tpl ) {
if ( angular.isDefined( tpl ) ) {
el = $sce.trustAsHtml(tpl);
element.html("");
element.append( el.toString() );
}
});
}
};
}
]);
@dhigginbotham
Copy link
Author

usage: <span compile-html template="{{editorial.content}}"></span>

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