类型“Promise<string>”不可分配给类型“string”

Non*_*one 2 promise typescript angular

如何放入服务的可变响应,然后在悬停时显示它?我试过这个:

toolTip: string;

async mouseover(params) {
    this.handle = setTimeout(() => {
        this.toolTip = this.checkSaldo(10, 'FRA');
        this.show = true;
    }, 4000);

}

checkSaldo(amount: any, currencyCode: any): Promise<string> {
    return new Promise((resolve) => {
        this.restService.getByParam('recalculatedSaldo', { amount: amount, currency: currencyCode }).subscribe(response => {
            resolve(response.payload);
        });
    })

}
Run Code Online (Sandbox Code Playgroud)

但我在变量上遇到错误toolTip

类型“Promise”不可分配给类型“string”

有什么建议吗?

Yon*_*hun 5

您不能将 分配到字段Promisestring

但是,您需要等待 Promise 回调并分配如下值:

this.checkSaldo(10, 'FRA').then((x) => {
    this.toolTip = x;
    ...
});
Run Code Online (Sandbox Code Playgroud)

StackBlitz 演示示例