0

I need to parse a string using ng-bind-html. This string contains some custom html tags in it. Which while parsing using ng-bind-html gives me an error for $sanitize:badparse.

Please see the fiddle for error: http://jsfiddle.net/8zS4h/2/

While reading questions in stackoverflow and in google I found that there could be a solution if I use $sce.trustAsHtml().

This solves my error issue but couldn't parse my custom html element. You can see this updated fiddle here: http://jsfiddle.net/8zS4h/3/

I am scratching hard my head to find a solution.

EDIT : Just to add more info, I am getting this string from a rss feed, so sometimes it can have "<http>" or "<http" tags also. Which is where it is failing. So if the string is like <http://www.<em>whitehouse</em>.gov/omb/circulars/a076/ should gives output like http://www.<em>whitehouse</em>.gov/omb/circulars/a076/

Mayank
  • 112
  • 8

1 Answers1

0

Well, I managed to get working tags like anchor, underline and bold without problem, look:

Fiddle

angular.module('ngBindHtmlExample', ['ngSanitize'])
  .controller('ngBindHtmlCtrl', ['$scope', function ngBindHtmlCtrl($scope) {
    $scope.myHTML =
        '<a href=\"http://google.com\">link</a> contests <u>of OMB</u> <b>Circular</b> A-76';
  }])
    .filter('to_trusted', ['$sce', function($sce){
        return function(text) {
            return $sce.trustAsHtml(text);
        }; 
}]);

seems like it's parsed correctly

Marcus
  • 341
  • 1
  • 8
  • This is fine but what to do if I have tags like "" or " – Mayank Jun 23 '14 at 12:22
  • it works fine, you just need to use correct syntax. eg. is fine, but this '' and ending element – Marcus Jun 23 '14 at 12:34
  • That's a problem, We are getting this string from rss feed and before inserting it into database, we are truncating the string with first 50 characters. Now it can have a closing '<' or can not. Thanks for your comment. – Mayank Jun 23 '14 at 12:43