calling getBlock() returning before service calls.Please help to wait until
the service return.
ngOnInit() {
this.blocks = this.commonService.getBlocks();
console.log("response"+this.blocks);
}
async getBlocks(){
var blockArr1 =[];
let _cs = this.contractService;
var dd;
var that = this;
var filter = this.contractService.web3.eth.filter({
address: this.contractService.boardConttractId,
fromBlock: 0
});
await filter.get(function(err, result) {
console.log("Filter ");
if(err) {
alert(err);
return;
}
if(!err){
console.log("result.sort ");
result.sort(function(a,b) {
return a.blockNumber - b.blockNumber;
});
for (var i = 0; i < result.length; ++i) {
blockArr1.push(_cs.web3.eth.getBlock(result[i].blockNumber));
dd = new Date(blockArr1[i].timestamp*1000);
blockArr1[i].datetime = dd.toLocaleString();
}
if(result.length === blockArr1.length){
return blockArr1;
}
}
});
}
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.