【发布时间】:2021-03-27 04:24:31
【问题描述】:
我正在尝试从我的 API 调用中获取数据,但使用的是 Promise。
interface SomeType {
status: string;
other?: string; // not used - delete
}
indexStatus(indexName: string): string {
// this.content = {};
const returnedPromise = this.indexStatusCall(indexName)
.then(returnData => {
this.content = returnData;
return returnData;
});
this.content = returnedPromise;
console.log("----this.content: ", returnedPromise);
return returnedPromise[0];
}
indexStatusCall(indexName: string): Promise < SomeType > {
return this.http.fetch('http:API-PATH/indices/' + indexNameReplaced + '?format=json&h=status')
.then(response => response.json())
.then(data => {
return data;
});
}
这是 console.log 显示的内容
如何获得我的“状态”值?
【问题讨论】:
标签: javascript api promise