[英]How to show angular data model as HTML?
I have a data-model that needs to be converted or show up as html. 我有一个数据模型,需要转换或显示为html。 Right now it just shows up as text. 现在,它只是显示为文本。
html HTML
<div ng-repeat="item in ornamentFigures" class="ornament-item">
<label for="ornament-{{item.id}}">{{item.svg}}</label>
<input type="radio" id="ornament-{{item.id}}" name="ornament-radio" />
</div>
controller 调节器
$scope.ornamentFigures = ornamentFigures.ornamentFigures;
service 服务
MyApp.service('ornamentFigures', function(){
this.ornamentFigures = [
{id:'03', name:'wit', svg:'<svg></svg>'},
{id:'03', name:'wit', svg:'<svg></svg>'},
{id:'03', name:'wit', svg:'<svg></svg>'},
];
return this;
});
Are you looking for ng-bind-html ? 您在寻找ng-bind-html吗?
Replace: 更换:
<label for="ornament-{{item.id}}">{{item.svg}}</label>
With: 附:
<label for="ornament-{{item.id}}" ng-bind-html="item.svg"></label>
Also include ngSanitize
in your module and include "angular-sanitize.js" in your application as per the documentation . 还包括ngSanitize
你的模块中,并在您的应用程序“角sanitize.js”按文档 。
Instead of binding the data as is, it will render as html. 与其按原样绑定数据,不如将其呈现为html。 Keep in mind there are security implications to this. 请记住,这涉及安全性。 You might want to try a different way if you can. 如果可以的话,您可能想尝试另一种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.