I need to dynamically compile html and pass it from a function as text. So, I have this code (simplified version for debugging purpose):
angular.module('app', [])
.run(function($rootScope, $compile){
var data = ["1","2"];
var html =
'<div>' +
'<ul>' +
'<li ng-repeat="score in data">{{score}}</li>' +
'</ul>'+
'</div>';
var el = angular.element(html);
$rootScope.data = data;
var result = $compile(el)($rootScope);
console.log(result.html());
})
Result:
<ul></ul>
So it seems that ngRepeat is not "repeating" the "li" element.
Why?
JsFiddle: http://jsfiddle.net/yoorek/K4Cmk/
(I know that DOM manipulation should be in a directive, etc., and I know how to do it the other way, but I need to understand why this does not work)
source
share