单元测试 – Jasmine单元测试:$compile从ng-repeat中产生注释

前端之家收集整理的这篇文章主要介绍了单元测试 – Jasmine单元测试:$compile从ng-repeat中产生注释前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么这条线
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,9] --></ul>'

我想看看< li>项目而不是评论.

你错过了 digest方法,一路走来
var e = $compile('<div><ul><li ng-repeat="item in [1,9]">{{item}}</li></ul></div>')(scope);
scope.$digest();
console.log(e.html());

这是我现在得到的输出

Safari 537.21 (Linux) LOG: '
<ul><!-- ngRepeat: item in [1,9] -->
<li ng-repeat="item in [1,9]" class="ng-scope ng-binding">1</li>
<li ng-repeat="item in [1,9]" class="ng-scope ng-binding">3</li>
<li ng-repeat="item in [1,9]" class="ng-scope ng-binding">5</li>
<li ng-repeat="item in [1,9]" class="ng-scope ng-binding">7</li>
<li ng-repeat="item in [1,9]" class="ng-scope ng-binding">9</li>
</ul>'
原文链接:https://www.f2er.com/angularjs/141483.html

猜你在找的Angularjs相关文章