使用async/await将Observable转换为Promise,并在调用API后设置本地变量。
示例代码:
async fetchData() {
try {
const data = await this.http.get('http://api.example.com/data').toPromise();
this.localVariable = data;
} catch (error) {
console.error(error);
}
}