为什么行
var scope = $rootScope.$new();
dump($compile('<ul><li ng-repeat="item in [1,3,5,7,9]">{{item}}</li></ul>')(scope));
结果:
'<ul class="ng-scope"><!-- ngRepeat: item in [1,3,5,7,9] --></ul>'
我希望看到<li>
件而非评论。
答案 0 :(得分:16)
你错过了digest
方法,一路走
var e = $compile('<div><ul><li ng-repeat="item in [1,3,5,7,9]">{{item}}</li></ul></div>')(scope);
scope.$digest();
console.log(e.html());
这是我现在得到的输出:
Safari 537.21 (Linux) LOG: '
<ul><!-- ngRepeat: item in [1,3,5,7,9] -->
<li ng-repeat="item in [1,3,5,7,9]" class="ng-scope ng-binding">1</li>
<li ng-repeat="item in [1,3,5,7,9]" class="ng-scope ng-binding">3</li>
<li ng-repeat="item in [1,3,5,7,9]" class="ng-scope ng-binding">5</li>
<li ng-repeat="item in [1,3,5,7,9]" class="ng-scope ng-binding">7</li>
<li ng-repeat="item in [1,3,5,7,9]" class="ng-scope ng-binding">9</li>
</ul>'