Scipion Scipion - 1 year ago 106
AngularJS Question

Angularjs convert string to html in view

I am currently trying to add links in my view. I do have links which basically contains html tags as strings.
I tried:

<p data-ng-repeat='i in links' >{$ $}</p>

which basically just deploy in my view : mylink

So I did try:

<p data-ng-repeat='i in links' ><span data-ng-bind-html=""></span></p>

It doesn't work though, any idea how could I achieve this ?


Answer Source

Add the $sce as a dependancy of the module

angular.module('myApp', ['$sce']);

When getting the links

angular.forEach($scope.links, function(value){ = $sce.trustAsHtml(;

Using Safe Contextual Escaping ($sce) and using trustAs delegate you're telling Angular that this value is safe to use within that context. In this example. $sce.trustAsHtml returns an object that angular can trust is safe to as HTML.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download