How to fix "10 $ digest () iterations achieved. Cancel!" error in Angular 1.2 filter?

I created a filter in AngularJS 1.2, which uses ShowdownJS to parse Markdown content in HTML:

App.filter('markdown', function( $sce ) {
    var converter = new Showdown.converter();
    return function (value) {
        var html = converter.makeHtml(value);
        return $sce.trustAsHtml(html);
    };
});

Template binding is done using ng-bind-html . This one gets the final HTML content, so it should display the content:

<div ng-bind-html="post.content | markdown"></div>

The filter works , but I get this error in the console because it returns the $ sce service , and MUST only return parsing > HTML string .

10 $digest() iterations reached. Aborting!

? - , html $sce.

EDIT: sanitize config, , .

$sceProvider.enabled(false);
+4
4

, - . , , . ng-bind-html .

:

app.filter('markdown', ['$sce', function( $sce ) {
    var converter = new Showdown.converter();
    var converted = {};

    return function (value) {
      if(converted.hasOwnProperty(value)) {
        return converted[value];
      }

      var html = converter.makeHtml(value);
      var trusted = converted[value] = $sce.trustAsHtml(html);
      return trusted;
    };
}]); 
+3

, - ngBindHtmlDirective, $sce.getTrustedHtml . , $sce (plnkr):

App.directive('simpleHtml', function() {
  return function(scope, element, attr) {
    scope.$watch(attr.simpleHtml, function (value) {
      element.html(scope.$eval(attr.simpleHtml));
    })
  };
})
+1

return $sce.trustAsHtml(html).toString();
0

, .

0

All Articles