7

为什么线

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>项目而不是评论。

4

1 回答 1

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>'
于 2013-05-24T13:04:02.773 回答