繁体   English   中英

ng-bind-html工作,但抛出错误

[英]ng-bind-html working, but throwing error

我正在使用ng-bind-html来呈现已清理的评论HTML。 这是我的HTML:

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

它工作 - HTML被渲染并正确显示。 但是我在Javascript控制台中收到以下错误:

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">

这是导致angular.js的问题的代码:

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

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

bindings变量最终成为字符串comment.Text ,这就是为什么它不支持方法push ,因为它不是数组。

我该怎么改变来解决这个问题?

你是对的.push只适用于数组。 使用此功能,您必须初始化变量

var bindings = new Array();

您也可以尝试使用.pushStack => http://api.jquery.com/pushstack/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM