此错误与AngularJS的ngTable插件有关。
我似乎有一个很奇怪的错误。基本上,我可以运行$scope.tableParams.reload()
两次而没有问题,但是在第三次执行时,以及随后的每次执行时,都会出现以下错误:
TypeError: Cannot set property '$data' of null at [removed]/ng-table.js:411:55
我相信这是所有相关的代码,但是如果有任何遗漏,请通知我:
$scope.lookupAddress = function(address){
var url = 'https://blockchain.info/multiaddr?cors=true&active='+address;
$scope.loading = true;
$scope.clearTableData();
$http.get(url).success(function(data){
$scope.loading = false;
$scope.loaded = true;
$scope.loadError = false;
glob = data;
//I believe the next few for loops, and the assignment of transactions, is not relevant to finding the code. That being said, I've included it because bugs hide where you least expect it.
for (i = data.txs.length -1; i > -1; i-- ){
var inputAddr = [];
for (z = 0; z < data.txs[i]['inputs'].length; z++){
inputAddr.push(data.txs[i]['inputs'][z]['prev_out']['addr'])
}
var outputAddr = [];
for (z = 0; z < data.txs[i]['out'].length; z++){
outputAddr.push(data.txs[i]['out'][z]['addr'])
}
transactions[i] = {
'Hash' : data.txs[i]['hash'],
'Amount' : data.txs[i]['result'] / 100000000,
'Balance' : data.txs[i]['balance'] / 100000000,
'InputAddress' : inputAddr,
'OutputAddress' : outputAddr,
'Date' : timeConverter(data.txs[i]['time'])
};
};
//You can also ignore this too... probably.
$scope.output = {
'BTC' : data.wallet.final_balance / 100000000, //Response in satoshi, so have to divide.
'Address' : address,
'Total Received': data.addresses[0].total_received / 100000000,
'Total Sent': data.addresses[0].total_sent / 100000000,
'Transactions' : transactions
};
//Enables new data to be loaded, e.g. on a new address.
if ($scope.tableParams){
$scope.tableParams.reload();
}
data = transactions;
$scope.tableParams = new ngTableParams({
page: 1,
count: 5, // items per page
sorting: {
Date: 'desc'
}
}, {
total: transactions.length,
getData: function($defer, params) {
data = transactions;
var orderedData = params.sorting() ? $filter('orderBy')(data, params.orderBy()) : data;
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
}).
error(function(data){
$scope.loadError = true;
});
}
$scope.clearTableData = function(){
transactions = [];
$scope.output = {}
if ($scope.tableParams){
$scope.tableParams.reload();
}
}
最佳答案
我知道这为时已晚,但是我想为寻求相同问题答案的其他人对此发表评论。
我也遇到了同样的问题,并通过按照以下URL中的示例进行了修复。
https://github.com/esvit/ng-table/blob/master/src/scripts/04-controller.js
创建ngTableParams实例后,我在代码中添加了以下代码行。
$scope.params.settings().$scope = $scope;