简体   繁体   English

动态angularjs模板

[英]Dynamic angularjs template

I am trying to create a directive this way - 我正在尝试以这种方式创建指令-

scope.nodeTemplate = '{{node.nodeText}}';

Part of template 模板的一部分

'<ul>' +
    '<li class="tree-node" data-ng-repeat="node in nodes">' +
        '<span>' + scope.nodeTemplate + '</span>' +
    '</li>' +
'</ul>'

Based on some condition I would like to change the nodeTemplate and it can be an html string like - 根据某些条件,我想更改nodeTemplate ,它可以是html字符串,例如-

'<input type="text"/>'

But the issue is when it try to do this thing angular does not render the html. 但是问题是当它尝试执行此操作时, angular无法呈现html。 It simply puts the html string. 它只是放置html字符串。 I am kind of stuck here. 我有点卡在这里。 Can someone suggest some solution? 有人可以提出一些解决方案吗?

您需要使用ng-bind-html-unsafe,例如:

'<span ng-bind-html-unsafe="nodeTemplate"></span>'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM