[英]Angular directive ng-bind-html is not working in some cases
我想我嘗試了堆棧溢出時提供的所有解決方案,但找不到答案。
我正在使用 angular 1.4.4 和 ng-repeat 指令,我想在表格行中顯示 HTML 注釋。 示例注釋是“測試注釋”
<tbody ng-show="dataLoaded">
<tr ng-repeat="comment in comments | filter: commentFilter | commentFilter: customCommentFilter | limitTo: 10 : (currentPage*10-10)">
<td ng-bind-html="comment.Comment | html">
</td>
</tr>
</tbody>
然后,在我的過濾器文件中,我使用以下過濾器:
// html filter (render text as html)
angular.module('app').filter('html', ['$sce', function ($sce) {
return function (text) {
return $sce.trustAsHtml(text);
};
此外,當我寫類似的東西時它正在工作
<td ng-bind-html="'<b>abc</b>' | html">
最后,當我寫一些類似的東西時
<td>
{{comment.Comment}}
</td>
評論顯示為<b>測試評論</b>
另外,我添加了 ngSanitize:
(function () {
'use strict';
var app = angular.module('app', [
// Angular modules
'ngCookies',
'ngRoute',
'ngAnimate',
'ngSanitize',
]);
...
...
})();
我的問題是,如何使 ng-bind-html 在我的示例中工作?
<tbody ng-show="dataLoaded">
<tr ng-repeat="comment in comments | filter: commentFilter | commentFilter: customCommentFilter | limitTo: 10 : (currentPage*10-10)">
<td ng-bind="comment.Comment">
</td>
</tr>
</tbody>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.