Ng-bind-html works, but throwing error

I use ng-bind-htmlHTML to render the sanitized comment. This is my html:

<span class="commentBody" ng-bind-html="comment.Text"></span>

It works - HTML is displayed and displayed correctly. But I see the following error in the Javascript console:

TypeError: Object doesn't support property or method 'push'
   at $$addBindingInfo (http://localhost:2239/Scripts/angular.js:6869:9)
   at ngBindHtmlLink (http://localhost:2239/Scripts/angular.js:20460:9)
   at invokeLinkFn (http://localhost:2239/Scripts/angular.js:8219:9)
   at nodeLinkFn (http://localhost:2239/Scripts/angular.js:7729:11)
   at compositeLinkFn (http://localhost:2239/Scripts/angular.js:7078:13)
   at compositeLinkFn (http://localhost:2239/Scripts/angular.js:7081:13)
   at publicLinkFn (http://localhost:2239/Scripts/angular.js:6957:30)
   at boundTranscludeFn (http://localhost:2239/Scripts/angular.js:7096:9)
   at controllersBoundTransclude (http://localhost:2239/Scripts/angular.js:7756:11)
   at ngRepeatAction (http://localhost:2239/Scripts/angular.js:24553:15) <span class="commentBody ng-binding" ng-bind-html="comment.Text">

This is the code causing the problem in angular.js:

  var bindings = $element.data('$binding') || [];

  if (isArray(binding)) {
    bindings = bindings.concat(binding);
  } else {
    bindings.push(binding);
  }

The variable bindingsends as a string comment.Text, so it does not support the method push, because it is not an array.

What should I change to fix this?

+4
source share
1 answer

You're right .push will only work with an array. Using this, you must initialize the variable

var bindings = new Array();

.pushStack = > http://api.jquery.com/pushstack/

0

All Articles