admin管理员组文章数量:1291688
This error is in regards to the ngTable plugin for AngularJS.
I seem to be having a really weird error. Basically, I can run $scope.tableParams.reload()
twice with no problem, but on the third execution, and every following one, I get the following error:
TypeError: Cannot set property '$data' of null at [removed]/ng-table.js:411:55
I believe this is all the relevant code, but if anything is missing let me know:
$scope.lookupAddress = function(address){
var url = ';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();
}
}
This error is in regards to the ngTable plugin for AngularJS.
I seem to be having a really weird error. Basically, I can run $scope.tableParams.reload()
twice with no problem, but on the third execution, and every following one, I get the following error:
TypeError: Cannot set property '$data' of null at [removed]/ng-table.js:411:55
I believe this is all the relevant code, but if anything is missing let me know:
$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();
}
}
Share
Improve this question
asked Apr 29, 2014 at 20:45
AdamAdam
411 silver badge3 bronze badges
1
- The code you're using to get your data (which you've marked as potentially unrelated) really is irrelevant; the problem lies in the $scope.tableParams.reload() call. Suggested an edit, but it got rejected. – Léo Lam Commented Aug 1, 2014 at 9:40
4 Answers
Reset to default 6I know this is too late, but I thought better to ment on this for others who seeking for a answer for the same issue.
I also had the same issue and managed to fix by following the example in following URL.
https://github./esvit/ng-table/blob/master/src/scripts/04-controller.js
I just added the following code line into my code after 'ngTableParams' instance creation.
$scope.params.settings().$scope = $scope;
Try adding:
,
$scope: { $data: {} }
after:
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()));
}
I had the same problem. When you initialize ngTableParams
, you need to specify all parameters: page
, count
, total
, and counts
, even if you are not using paging, because otherwise the $scope
property of setting will be set to null somehow during merging all settings together.
I also faced the same problem and solved it by adding reload:
$scope.tableParams as below
$scope.tableParams = new ngTableParams({
page: 1,
count: 25,
***reload: $scope.tableParams***
},
本文标签:
版权声明:本文标题:javascript - In ngTables, running $scope.tableParams.reload() for the third time results in TypeError: Cannot set property & 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741536143a2384036.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论