angularjsangularjs-ng-repeatng-bind-html

ng-repeat inside ng-bind-html


If I have a div as follows

<div ng-bind-html="myHtml"></div>

and myHtml is defined as follows

$scope.names = ['A','B','C'];
$scope.myHtml = "<p ng-repeat=\"name in names\" ng-bind=\"name\"></p>";

Why ng-repeat is not processing in this case?


Solution

  • You can to use bind-html-compile directive instead bind-html

    ngBindHtml we use for HTML without angular directives like ng-repeat or ng-model but single DOM


    Angular should know about new changes and enter them to digest cycle. For that reason we need merge ngBindHtml with $compile. This is a purpose of bind-html-compile directive that should do both things in one.