我有一些 Angular 表达式,其中包含来自数据库的数据。其中一些数据在数据库中包含 HTML 标签,并且应该在 HTML 中进行解码。
Javascript函数:
vm.showTechnicalSupport = function () {
$http.get('Navigation/GetTechSupportInformation').success(function (data) {
vm.techSupportHours = data.techSupportHours;
})
}
HTML:
<span>{{ vm.techSupportHours}}</span>
问题是 techSupportHours 显示原始 HTML 标签而不是渲染标记。 例如,页面上可见地显示 br 标签。有没有办法修改我的 Angular 表达式来解码此数据?
最佳答案
有一个名为 ng-bind-html 的指令这就是您正在寻找的。 所以只需将您的 html 模板更改为:
<span ng-bind-html="vm.techSupportHours"></span>
关于javascript - Angular - 将字符串解码为 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34777119/