In this plunk我有一个用UL元素声明的指令。在指令元素参数中获取HTML标记
<directive>
<ul>
<li id="0">xxx 0</li>
<li id="1">xxx 1</li>
<li id="2">xxx 2</li>
</ul>
</directive>
我试图通过分析向链路功能element
参数检索这些,但我只让他们在innerHTML之中。我需要的是将li
元素的ID和文本作为DOM获取。有任何想法吗?
angular.module('app', []);
angular.module('app').directive('directive', function() {
var directive = {};
directive.restrict = 'AE';
directive.scope = true;
directive.link = function(scope, element, attrs) {
console.log(element)
};
return directive;
});
你想这样的结果: http://plnkr.co/edit/baeGA2wbMuZkQRW5vlY7?p=preview – Natiq
@Nati不,它仍然是这样的纯文本。 – Michelangelo
这看起来真的倒退了。什么生成的HTML首先? – charlietfl