I've encountered similar questions before, such as this one: (forEach Typescript TS2339 "does not exist on type 'void'")
Despite that, I'm still struggling to solve my specific issue.
ngOnInit() {
var __this = this;
this.historianService.getHistorian()
.then(function(res){
console.log(res)
res.forEach(transaction => {
__this.results.push(res);
})
})
}
The output of console.log(res) is:
(7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
0
:
{$class: "org.hyperledger.composer.system.HistorianRecord", transactionId: "1dec5c91d047deebb588d69e4844ccdda03b3621783bc6c8c82b286e6e4c3d65", transactionType: "org.hyperledger.composer.system.IssueIdentity", transactionInvoked: "resource:org.hyperledger.composer.system.IssueIden…bb588d69e4844ccdda03b3621783bc6c8c82b286e6e4c3d65", participantInvoking: "resource:org.hyperledger.composer.system.NetworkAdmin#admin", …}
1
:
{$class: "org.hyperledger.composer.system.HistorianRecord", transactionId: "2114019f-7179-4f0f-b0fc-bc25d116f2eb", transactionType: "org.hyperledger.composer.system.ActivateCurrentIdentity", transactionInvoked: "resource:org.hyperledger.composer.system.ActivateC…rentIdentity#2114019f-7179-4f0f-b0fc-bc25d116f2eb", identityUsed: "resource:org.hyperledger.composer.system.Identity#…f1adb8973507f6c7316039a49d92ab007abccf3a882b7dad3", …}
2
:
...
length
:
7
__proto__
:
Array(0)
...
Although the returned variable res has the forEach function associated with it, I am unable to use it as expected:
res.forEach(transaction => {
__this.results.push(res);
})
This results in an error message:
Property 'forEach' does not exist on type 'void | Response'. Property forEach does not exist on type 'void'
EDIT: Definition of getHistorian function:
getHistorian(){
const headers = new Headers({'Content-Type': 'application/json'});
const options = new RequestOptions({headers: headers});
var __this = this;
return this.http.get('http://'+ this.ip +':3000/api/system/historian?access_token=' + this.access_token,options)
.toPromise()
.then(function(res){
res = res.json();
return res;
})
.catch(e => {console.log(e); //print error if there is one
});