[英]Angular - decode string as HTML
I have some angular expressions that contain data coming from a database. 我有一些角度表达式,其中包含来自数据库的数据。 Some of this data contain HTML tags in the database and should be decoded as such in the HTML. 其中一些数据在数据库中包含HTML标记,因此应该在HTML中进行解码。
Javascript function: JavaScript函数:
vm.showTechnicalSupport = function () {
$http.get('Navigation/GetTechSupportInformation').success(function (data) {
vm.techSupportHours = data.techSupportHours;
})
}
HTML: HTML:
<span>{{ vm.techSupportHours}}</span>
The problem is techSupportHours is displaying raw HTML tags instead of rendering markup. 问题是techSupportHours正在显示原始HTML标签,而不是呈现标记。 For example, there are br tags being displayed visibly on the page. 例如,在页面上可见地显示了br标签。 Is there a way to modify my angular expression to decode this data? 有没有办法修改我的角度表达式以解码此数据?
There is a directive called ng-bind-html which is what you are looking for. 您正在寻找一个名为ng-bind-html的指令。 So just change your html template to be: 因此,只需将您的html模板更改为:
<span ng-bind-html="vm.techSupportHours"></span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.