ng-bind-html-unsafe在Angular 1.2中被删除
我试图实现的东西,我需要使用ng-bind-html-unsafe。在文档和github提交他们说:
ng-bind-html provides ng-html-bind-unsafe like behavior (innerHTML’s the result without
sanitization) when bound to the result of $sce.trustAsHtml(string).
你怎么做到这一点?
应该是:
原文链接:https://www.f2er.com/angularjs/147774.html<div ng-bind-html="trustedHtml"></div>
加上你的控制器:
$scope.html = '<ul><li>render me please</li></ul>'; $scope.trustedHtml = $sce.trustAsHtml($scope.html);
而不是旧的语法,在那里你可以直接引用$ scope.html变量:
<div ng-bind-html-unsafe="html"></div>
正如几个评论者指出的,$ sce必须在控制器中注入,否则你会得到$ sce未定义的错误。
var myApp = angular.module('myApp',[]); myApp.controller('MyController'['$sce',function($sce) { // ... [your code] }]);