I face the problem that I get some string from the server that represents an html and I need to parse style attrs for some nodes and then show this html inside the view with Angular.
So I see this answer https://stackoverflow.com/a/494348/1022726 that helps me to create an html node from a string then I go over each item and change styles. In the end I do $sce.trustAsHtml with the value of innerHTML.
I have this code http://plnkr.co/edit/HUfAGR2uNMwb48rqXbkk?p=preview
<div ng-bind-html="trustedHtml"></div>
function($scope, $sce) {
var s = '<h1 style="color: red; font-size: 16px;">Subheader</h1><p style="font-size: 12px;">text</p>';
var div = document.createElement('div');
div.innerHTML = s;
$(div).find("*").each(function () {
$(this).height('100px');
});
$scope.trustedHtml = $sce.trustAsHtml(div.innerHTML);
}]);
I want to know if there are any better ways to parse a string that represents html and then show that html in the view. Any help is appreciated.