我似乎無法將我在這裏做錯的事情包圍在我的腦海裏。我試圖從php文件中提取json數據,然後將其顯示在我的Angular應用程序中。AngularJS TypeError:無法讀取屬性'insertBefore'null
我app.js:
var app = angular.module("MyApp", []);
app.controller("ClientHealthCtrl", function($scope, $http) {
$http.get('json.php').
success(function(data, status, headers, config) {
$scope.rows = data;
}).
error(function(data, status, headers, config) {
// log error
});
});
我的HTML:
<body class="skin-black" ng-app="MyApp">
...
<tbody ng-controller="ClientHealthCtrl">
<tr class="link_back" ng-repeat="Computer in rows">
<td><a href="#cid={{Computer.id}}">{{Computer.ComputerName}}</a></td>
<td><i class="fa fa-fw fa-check-square" style="color:#008000;"></i>{{Computer.WmiTest}}</td>
<td><i class="fa fa-fw fa-check-square" style="color:#008000;"></i>{{Computer.SmsClientService}}</td>
<td><i class="fa fa-fw fa-check-square" style="color:#008000;"></i>{{Computer.McAfeeFrameworkService}}</td>
<td><i class="fa fa-fw fa-check-square" style="color:#008000;"></i>{{Computer.RemoteManagement}}</td>
</tr>
</tbody>
導致...
TypeError: Cannot read property 'insertBefore' of null
at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:2067:13
at forEach (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:113:18)
at forEach.after (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:2066:5)
at Object.JQLite.(anonymous function) [as after] (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:2104:17)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:13294:22
at https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:3745:29
at Object.<anonymous> (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:13293:13)
at Object.Scope.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:7693:38)
at Object.Scope.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:7894:24)
at done (https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js:8883:20)
enter code here
您是否確定數據模式與您期望的相同?你是否已經在成功處理程序中註銷了「數據」的值? – badsyntax 2014-09-29 15:15:46
添加console.log(JSON.stringify($ scope.rows));成功處理程序在控制檯中正確顯示json內容。所以如果沒有別的我知道$ scope.rows不是null。 – 2014-09-29 15:46:30
我有同樣的錯誤,但發現它是由ng-include指令引起的,所以請確保在代碼中檢查該錯誤。 – AlexandruC 2014-10-23 15:06:29