基本上,我正在做的是从我的服务器请求模板。这是一个简短的例子:AngularJS:使用字符串中的角度变量从范围变量呈现HTML
$scope.template = {
'title': 'default',
'description': 'default template',
'html': '<html><head><style>body {background: red;}</style></head><body>{{data.name}}</body></html>'
}
$scope.data = {
name: 'John'
}
这是我从我的服务器收到的JSON对象。我想把它渲染到DOM中。会显示什么,就是$scope.name
中的商店。
我有这个在我的角度
app.filter("trust", ['$sce', function($sce) {
return function(htmlCode){
return $sce.trustAsHtml(htmlCode);
};
}]);
这在我的HTML
<div ng-bind-html="template.html | trust"></div>
这使得HTML,但叶{{名}}为{{名}},当它应该说约翰。
我添加了一个https://plnkr.co/edit/5XwTMRTK83KntRP5LE8I?p=preview – nmanikiran
知道更多阅读https://docs.angularjs.org/api/ng/service/$compile – nmanikiran
@ManiKiran谢谢,我用您的解决方案 – notacodemonkey