簡體   English   中英

Angular 9 http.get 未執行

[英]Angular 9 http.get not executing

我無法讓我的任何服務 http 調用突然執行。 (他們正在工作)所以我只創建了一個簡單的健全性檢查 controller 方法和服務方法,它不僅不返回任何內容,而且 http 根據 Chrome 開發工具/網絡選項卡甚至永遠不會執行。

Controller 方法:

    sanityCheck(){
        this.accountService.test().subscribe(
            res => {
              console.log("res:",res); //We never get here
            }
          );
    }

服務電話

    test():Observable<any> {
        //This line executes, but no network call to postman-echo ever gets made.
        return this.http.get("https://postman-echo.com/get?foo1=bar1&foo2=bar2", httpOptions)
    }

    const httpOptions = {
      headers: new HttpHeaders({
        'Content-Type':  'application/json'
      })
    };

我敢肯定這是我忽略的簡單事情,因為它以前有效。

我最終確定我已將 HttpClientTestingModule 添加到 app.module.ts 並將其添加到導入部分。

該模塊完全短路了所有 http 調用,並且很難排除故障,因為它完全靜音 - 沒有錯誤,沒有響應。

抱歉,如果這個答案只是一個無禮的錯誤,但這是一個非常棘手的問題,答案很少,希望這可以幫助其他在類似問題上苦苦掙扎的人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM