我有一个名为$ scope.transactions = [....]的对象数组,它有正确的值。但是当我在ng-repeat中访问它时,如下所示返回上面的内容 错误。
控制器代码:
application.controller("custTransactionCtrl", function($scope, StbetServices) {
$scope.transactions=[];
.....
.......
$.ajax({
url: 'CustomerTransaction',
type: "POST",
data: {
fromDate: fromDate,
toDate: toDate,
type:$scope.selectedItem.id
},
success: function(data1) {
$scope.transactions = JSON.parse(data1);
},
error: function(jqXHR) {
console.log(jqXHR.responseText);
}
});
我在html中使用了 Transactions 数组,如下所示:
我的HTML :
<tbody>
<tr ng-repeat="t in transactions">
<td align="left">{{t.transactionDescription}}</td>
<td align="left">{{t.transactionDate}} </td>
<td align="left">{{t.transactionAmount}}</td>
<td align="left">{{t.customerAccount.id}}</td>
<td align="left">{{t.transactionReference}}</td>
<td align="left">{{t.transactionReference2}}</td>
</tr>
</tbody>
这将返回****TypeError: Cannot read property 'insertBefore' of null****
,完整的错误消息为:
TypeError: Cannot read property 'insertBefore' of null
at http://192.168.1.222:8080/stbet/lib/angular.js:2247:13
at forEach (http://192.168.1.222:8080/stbet/lib/angular.js:133:18)
at forEach.after (http://192.168.1.222:8080/stbet/lib/angular.js:2246:5)
at Object.JQLite.(anonymous function) [as after] (http://192.168.1.222:8080/stbet/lib/angular.js:2301:17)
at http://192.168.1.222:8080/stbet/lib/angular.js:14038:22
at publicLinkFn (http://192.168.1.222:8080/stbet/lib/angular.js:4095:29)
at Object.ngRepeatWatch (http://192.168.1.222:8080/stbet/lib/angular.js:14037:13)
at Object.$get.Scope.$digest (http://192.168.1.222:8080/stbet/lib/angular.js:8090:47)
at Object.$get.Scope.$apply (http://192.168.1.222:8080/stbet/lib/angular.js:8304:24)
at HTMLButtonElement.<anonymous> (http://192.168.1.222:8080/stbet/lib/angular.js:13255:17)
更新:
请在下面找到控制台输出:
答案 0 :(得分:1)
这是因为Angular编译以及如何绑定数据。您必须在ng-if="transactions"
属性中添加tbody
,如下所示:
<tbody ng-if="transactions">
<tr ng-repeat="t in transactions">
<td align="left">{{t.transactionDescription}}</td>
<td align="left">{{t.transactionDate}} </td>
<td align="left">{{t.transactionAmount}}</td>
<td align="left">{{t.customerAccount.id}}</td>
<td align="left">{{t.transactionReference}}</td>
<td align="left">{{t.transactionReference2}}</td>
</tr>
</tbody>
坦克向哈萨辛寻求帮助。更多信息请访问:Angularjs: TypeError: Cannot call method 'insertBefore' of null