I have a dashboard dynamic and there is a json that I fill with elements html in format text, for example:
var items = [
{"id": "panel1", "description": "<div><a ui-sref='page1'>link a</a></div>"},
{"id": "panel2", "description": "<div><a ui-sref='page2'>link b</a></div>"}
];
vm.items = items;
but when I do the ng-repeat on html it isn't turning the attribute in angular element, How I do to work this?
This is my html
<li class="dashboard-panel" data-ng-repeat="item in dashboardCtrl.items" data-ng-class="item.id == 'novo' ? 'background-new-panel' : ''">
<div class="content" id="{{item.id}}" data-ng-bind-html="item.descricao | trustAsHtml" style="display: block;"></div>
</li>
Code of solution:
return {
restrict: 'A',
replace: true,
link: function (scope, element, attrs) {
scope.$watch(attrs.ngHtmlCompile, function (html) {
element[0].innerHTML = html;
$compile(element.contents())(scope);
});
}
};