我使用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
,因为它不是数组。
我应该修改什么来解决这个问题?
答案 0 :(得分:0)
你是对的.push只适用于数组。使用此功能,您必须初始化变量
var bindings = new Array();
您也可以尝试使用.pushStack =&gt; http://api.jquery.com/pushstack/