Angular JS 在标签中显示 HTML [英] Angular JS shows HTML within the tag
本文介绍了Angular JS 在标签中显示 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 ng-bind-html-unsafe
属性在模板中插入 HTML.但由于某种原因它不起作用.
I am trying to insert HTML inside template using ng-bind-html-unsafe
attribute. But for some reason its not working.
我的代码:
<tr class="white two-button" ng-repeat="(key,value) in recommendations | ojoScoreFilter:ojoScore | relevancyScoreFilter:relevancyScore | orderBy:predicate:reverse">
<td>
<div ng-bind-html-unsafe="value.button"></div>
</td>
</tr>
我看不到 HTML.如果我将 ng-bind-html-unsafe="value.button"
更改为 ng-bind-html-unsafe="{{value.button}}"
那么它显示 HTML 但在属性内,类似这样:
I am not able to see the HTML.
If I change ng-bind-html-unsafe="value.button"
to ng-bind-html-unsafe="{{value.button}}"
then it shows HTML but within the attribute, something like this:
<div ng-bind-html-unsafe="<a class="action_hrefs full-width bgcolor10 purple-hover flat-button flat-white-button btn" data-value="947" href="#"><i class="fa fa-lock"></i> Unlock</a>"></div>
推荐答案
好的,我找到了解决方案:
Ok I found solution for this:
JS:
$scope.renderHtml = function(html_code)
{
return $sce.trustAsHtml(html_code);
};
HTML:
<p ng-bind-html="renderHtml(value.button)"></p>
这篇关于Angular JS 在标签中显示 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文