您不需要处理$ sce即可达到目的。
您可以将
HTMLas字符串传递给指令。在指令中编译后,它将起作用。
在
HTML您需要的地方
directive
<dir id="dir" content="myVal"></dir>
在
myVal控制器中设置其他值
$scope.myVal = '<button ng-click='buttonClick()'>I'm button</button>'; // HTML as string
的
directive
myApp.directive('dir', function($compile, $parse) { return { restrict: 'E', link: function(scope, element, attr) { scope.$watch(attr.content, function() { element.html($parse(attr.content)(scope)); $compile(element.contents())(scope); }, true); } } })检查
[**Demo**](http://plnkr.co/edit/v02xk1o3ORKaptzo40pj?p=preview)



