Created
October 23, 2014 14:18
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() ); | |
} | |
}); | |
} | |
}; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage:
<span compile-html template="{{editorial.content}}"></span>