【发布时间】:2025-12-01 09:30:01
【问题描述】:
我需要将 $scope.htmlView 标记呈现到 html 视图中。
我已经尝试过使用ng-bind-html。它呈现 html 标签,但范围变量值不会出现。
如何同时呈现 html 标记和范围变量值?
这是控制器:
$scope.newObj = {
billStatus : true;
eventTime : "2015-01-10"
};
$scope.htmlView = '<p>{{newObj.eventTime}}</p> <div style="margin-top: -15px;"><md-checkbox ng-checked="{{newObj.billStatus}}" style="margin-left: 0px;" aria-label="Bilable"><span style="margin-left:0px;">Bilable</span> </md-checkbox></div>'
预期结果是:
<p> 2015-01-10</p>
<div style="margin-top: -15px;">
<md-checkbox ng-checked="true" style="margin-left: 0px;" aria- label="Bilable">
<span style="margin-left:0px;">Bilable</span>
</md-checkbox>
</div>
我在互联网上搜索了几天,但仍然找不到解决此问题的方法。请帮我。谢谢。
【问题讨论】:
-
你试过这样做
$sce.trustAsHtml(string)trustAsHtml 吗? -
参考这里 (*.com/questions/18157305/…)
-
检查更新的答案。如果你需要变量,你必须使用 $compile 来评估它们