2017-04-06 489 views
0

我是打字稿的新手。基本上我有一個typecript GET函數,我想傳遞一個ID來獲取特定的記錄。我在返航線上遇到這個錯誤。在發佈之前,我研究了這一點,但無法獲得與我的場景接近的內容。幫助讚賞!TypeScript:無法調用其類型缺少呼叫簽名的表達式

錯誤TS2349無法調用其類型缺少呼叫 簽名的表達式。

private getRecordRequestUrl = 'http://localhost/Service/api/ReservationRequest/GetRequestById'; 

getRecordRequest(RequestId: number): Promise<ReservationModel[]> { 
     return this.http.get(this.getRecordRequestUrl(RequestId)) 
      .toPromise() 
      .then(response => response.json().Data as ReservationModel[]) 
      .catch(this.handleError); 
} 
+1

'getRecordRequestUrl'是一個字符串。你正試圖在'this.getRecordRequestUrl()'中調用它。 TypeScript的錯誤實際上就是爲了警告你,它會這樣做。 – deceze

回答

0

getRecordRequestUrl是一個字符串,而不是一個功能

但行return this.http.get(this.getRecordRequestUrl(RequestId))你怎麼稱呼它像它會是一個函數。

1

this.getRecordRequestUrl不是函數,它只是一個字符串。如果要將RequestId添加到它,則應連接該值,例如:return this.http.get(this.getRecordRequestUrl + '/' + RequestId)

相關問題