Wednesday, August 6, 2014

AngularJS: Render HTML tags in a string

Even HTML escape renders as text string not html without $sce.trustAsHtml in AngularJS.

Reason:
The interpolation directive will do the escaping of any HTML content found in the model in order to prevent HTML injection attacks.


Here is what I got:

<span class="headSpanLink" ng-click="searchCall(m.Id,-1)" ng-bind-html='transform(m.Disc)'></span>




    $scope.transform =function(n){      
   if( n!='undefined' ){
        var t = $sce.trustAsHtml(n.split(' ').join("<br>"));
        console.log(t);
        return t;
         
        }
 }

No comments:

Post a Comment