How can I pass in a service to a promise? I am trying to create a promise that will resolve when all the http request come back. Right now this.jiraService is undefined. Is there anyway to pass it to the constructor of the promise?
export class JiraComponent {
private stories:Map<string,number> = new Map<string,number>();
constructor(private jiraService:JiraService) {
}
ngOnInit() {
this.jiraService.search()
.then(x => this.getKeys(x['issues']))
.then(keys => this.getLogs(keys))
.then(x => console.log(this.stories));
}
getKeys(issues:Array<Object>) {
let keys = new Array<string>();
for (var i of issues) {
keys.push(i['key']);
}
return keys;
}
getLogs(keys:Array<string>) {
return new Promise(function (resolve, reject) {
let count = 0;
for (var k of keys) {
this.jiraService.worklog(keys[0]).then(x => {
count++;
console.log(x);
if (!this.stories.get(k)) {
this.stories.set(k, x['timeSpentSeconds']);
}
else {
this.stories.set(k, this.stories.get(k) + x['timeSpentSeconds']);
}
if (count == keys.length) {
resolve();
}
});
}
});
}