Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasmine unit tests: $compile produces comment out of ng-repeat

Why the line

var scope = $rootScope.$new();
dump($compile('<ul><li ng-repeat="item in [1,3,5,7,9]">{{item}}</li></ul>')(scope));

results in:

'<ul class="ng-scope"><!-- ngRepeat: item in [1,3,5,7,9] --></ul>'

I would like to see <li> items rather than comment.

like image 853
Paul Avatar asked May 24 '13 12:05

Paul


1 Answers

you're missing the digest method to go all the way

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());

This is the output I get now:

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>'
like image 55
Eduard Gamonal Avatar answered Oct 11 '22 16:10

Eduard Gamonal