我是AngularJS的新手。我希望 NOT 转义HTML标记,所以
<!-- <div>{{article.content}}</div> -->
<div ng-bind-html="{{article.content}}"></div>
但是没有任何东西被渲染出来。
答案 0 :(得分:3)
你不需要大括号:
<div ng-bind-html="article.content"></div>
你还需要确保角度知道它在你的控制器中是安全的:
$sce.trustAsHtml($scope.article.content);
答案 1 :(得分:2)
我认为这会对你有所帮助。
var app = angular.module('app', ['ngSanitize']);
app.controller('appCtrl', ['$scope', '$sce', ctrl]);
function ctrl($scope, $sce) {
$scope.getContent = function() {
return "shohel rana";
};
}
<body ng-controller="appCtrl">
<h1>Hello Plunker!</h1>
<div ng-bind-html="getContent()"></div>
</body>