第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

“訂閱”類型缺少“Observable<StringMap<any>>”類型中的以下屬性

“訂閱”類型缺少“Observable<StringMap<any>>”類型中的以下屬性

大話西游666 2021-09-30 13:57:56
錯(cuò)誤:“訂閱”類型缺少“可觀察>”類型中的以下屬性:_isScalar、源、運(yùn)算符、電梯和其他 6 個(gè)。ts(2740)在這里我附上了我的代碼。在這里,在我的例子中,我有兩個(gè)方法返回一個(gè)可觀察的,但是 getByTypeData 和 getByType。但是,在從 getByTypeData() 返回 this.getByType(type).. 時(shí),我遇到了上述錯(cuò)誤。PS:我想在我的組件中訂閱 getByTypeData 應(yīng)該返回一個(gè)可觀察的。我是 RXJS 的新手...  /*   interface IStringMap<T> {        [index: string]: T;    }    */    getByTypeData(type: string, ignoreApi = false): Observable<stringMap<any>> {        if (ignoreApi) {            this.handleConfig(type);        }        return this.getByType(type)            .subscribe(response => {                const config = response.result ? response.data : {};                return this.handleConfig(type, config);            });    }  // This method in another file (Just for reference)    getByType(type: string): Observable<stringMap<any>> {        return this.httpClient.get(`get url`);    }      handleConfig(type: string, config: stringMap<string | number> = {}): Observable<stringMap<any>> {        if (type === this.types) {            config.token = this.anotherservice.GetKey('mykey');            if (config.token) {                // logic            }        }        if (type === this.types) {            // logic        }        return of(config);    }
查看完整描述

1 回答

?
三國(guó)紛爭(zhēng)

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊

正如評(píng)論中指出的那樣,您返回的是 aSubscription而不是返回Observable. 我建議您閱讀文檔以了解它們之間的區(qū)別。


在您的特定情況下,我建議您嘗試以下操作:


getByTypeData(type: string, ignoreApi = false): Observable<stringMap<any>> {

    if (ignoreApi) {

        return this.handleConfig(type);

    }

    return this.getByType(type).pipe(

        switchMap(response => {

            const config = response.result ? response.data : {};

            return this.handleConfig(type, config);

        })

    );

}

switchMap 是一個(gè)需要使用如下語(yǔ)句導(dǎo)入的 rxjs 運(yùn)算符:


import { switchMap } from 'rxjs/operators'

可以在此處找到有關(guān)此運(yùn)算符的文檔

一篇解釋映射運(yùn)算符的好文章在這里


查看完整回答
反對(duì) 回復(fù) 2021-09-30
  • 1 回答
  • 0 關(guān)注
  • 348 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)