我有代码:
htmlObject = '<div status-box></div>';
template = $compile(htmlObject)($scope);
$scope.$digest();
console.log(template);
var templateAsHtml = template.html();
console.log(templateAsHtml);
和输出:从第一个console.log:
{0: <div status-box="" class="ng-scope"></div>, length: 1}
从第二个开始:
''
似乎当我调用.html时,它只是不进行转换而为空。
当您请求.html()
一个元素时,您将得到innerHTML
它。由于'<div status-box></div>'
没有子节点,因此行为是正确的。如果要返回包含对象本身的HTML,则需要使用outerHTML
function。
var templateAsHtml = template[0].outerHTML;
console.log(templateAsHtml);
查看文档:
注意:[0]
用来访问包装对象内部的原始JavaScript对象。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句