var app =angular.module(‘myApp‘,[‘ngSanitize‘]); app.controller(‘ctrl‘,function($scope,$sce){ $scope.myHtml = ‘<p >an html ‘ + ‘<em onclick="this.textContent=‘code_bunny‘">click here</em> ‘ + ‘snippet</p>‘; $scope.trustHtml = $sce.trustAsHtml($scope.myHtml) }
$sanitize会把标签的属性都移除,以及绑定在元素上的事件.仅保留了标签和内容