[英]Angular directive ng-bind-html is not working in some cases
I think I tried all the solutions presented on stack overflow but couldn't find an answer.我想我尝试了堆栈溢出时提供的所有解决方案,但找不到答案。
I am using angular 1.4.4 and ng-repeat directive and I want to display a HTML comment inside a table row.我正在使用 angular 1.4.4 和 ng-repeat 指令,我想在表格行中显示 HTML 注释。 A sample comment is ' Test comment '示例注释是“测试注释”
<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>
Then, inside my filter file I am using the following filter:然后,在我的过滤器文件中,我使用以下过滤器:
// html filter (render text as html)
angular.module('app').filter('html', ['$sce', function ($sce) {
return function (text) {
return $sce.trustAsHtml(text);
};
Also, it is working when I write something like此外,当我写类似的东西时它正在工作
<td ng-bind-html="'<b>abc</b>' | html">
Finally, when I write something like最后,当我写一些类似的东西时
<td>
{{comment.Comment}}
</td>
The comment is displayed as <b>Test comment</b>评论显示为<b>测试评论</b>
Also, I have added ngSanitize:另外,我添加了 ngSanitize:
(function () {
'use strict';
var app = angular.module('app', [
// Angular modules
'ngCookies',
'ngRoute',
'ngAnimate',
'ngSanitize',
]);
...
...
})();
My question is, how can I make ng-bind-html work in my example?我的问题是,如何使 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.