Is it possible to create an HTML fragment in an AngularJS controller and have this HTML shown in the view?
(是否可以在AngularJS控制器中创建HTML片段并将该HTML显示在视图中?)
This comes from a requirement to turn an inconsistent JSON blob into a nested list of id : value
pairs.
(这是因为需要将不一致的JSON Blob转换为id : value
对的嵌套列表。)
Therefore the HTML is created in the controller and I am now looking to display it. (因此,在控制器中创建了HTML,现在我希望显示它。)
I have created a model property, but cannot render this in the view without it just printing the HTML.
(我已经创建了一个模型属性,但是如果不打印HTML,就无法在视图中呈现它。)
Update
(更新资料)
It appears that the problem arises from angular rendering the created HTML as a string within quotes.
(看起来问题出在将创建的HTML角化为引号内的字符串而引起。)
Will attempt to find a way around this. (将尝试找到解决此问题的方法。)
Example controller :
(控制器示例:)
var SomeController = function () {
this.customHtml = '<ul><li>render me please</li></ul>';
}
Example view :
(示例视图:)
<div ng:bind="customHtml"></div>
Gives :
(给出:)
<div>
"<ul><li>render me please</li></ul>"
</div>
ask by Swaff translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…