Как я могу передать сервис на обещание? Я пытаюсь создать обещание, которое решит, когда все http-запросы вернутся. Прямо сейчас this.jiraService не определено. Есть ли все-таки передать его конструктору обещания?Угловая 2/typescipt pass service to prom
Спасибо!
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();
}
});
}
});
}
См http://stackoverflow.com/a/20279485/294949 – danh