你只需要用ng-bind-html绑定原始的html内容。不需要在控制器中做任何其他事情。解析和转换由ngBindHtml指令自动完成。(关于此:预计美元,请阅读How does it work部分)。所以,在你的情况下<div ng-bind-html="preview_data.preview.embed.html"></div>会做这项工作。
var app = angular.module('common.module', []);
// html filter (render text as html)
app.filter('html', ['$sce', function ($sce) {
return function (text) {
return $sce.trustAsHtml(text);
};
}])
Usage:
<span ng-bind-html="yourDataValue | html"></span>
Now - I don't see why the directive ng-bind-html does not trustAsHtml as part of its function - seems a bit daft to me that it doesn't
Anyway - that's the way I do it - 67% of the time, it works ever time.
angular.module('myAppWithSceDisabledmyApp', []).config(function($sceProvider) {
// Completely disable SCE. For demonstration purposes only!
// Do not use in new projects.
$sceProvider.enabled(false);
});