How do I output data from a service as HTML?

I’m using the example service in a tabbed app to output some data. The data has HTML tags within it but when I call the data it outputs the tags instead of parsing it as HTML.

Example:

var issues = [{
    id: 0,
    image: 'IMAGEURL',
    subtitle: 'SUBTITLE',
    icon: 'ICON',
    audio: 'audio/FILENAME.mp3',
    description: '<p>Example text</p>'
}];

When I use {{issue.description}} it outputs the description literally as:

<p>Example text</p>

How can I call data in this way and have it parse the HTML?

Thanks

In your view try putting something like:

<div ng-bind-html="renderAsHtml(issue.description)"></div>

Then in your controller include $sce and define renderAsHtml like:

$scope.renderAsHtml = function(html)	{
	return $sce.trustAsHtml(html);
}
1 Like

Works perfectly, thanks a lot!