2017-06-28 71 views
0

ID地址在這裏我嘗試值id傳遞給我的API,請幫助我如何我通過我寫代碼如何寫角2

**StateUrl: "http://localhost:54873/Api/Home/GetStates"** This is my url i wana 2 pass it By using my value This is my code 

GetStatesById(id: number): Observable<State> { 
      const stsurlById = `${this.StateUrl}/${id}`; 
      return 
      this._http.get(stsurlById).map(this.extractData).catch(this.handleError) 
     } 

這裏即時得到錯誤爲不可達代碼dected

回答

1

plase回覆此編碼

GetStatesById(id: number): Observable<State> { 
     const url = `${this.StateUrl}/${id}`; 
     return this._http.get(url) 
      .map(this.extractData) 
      // .do(data => console.log('getProduct: ' + JSON.stringify(data))) 
      .catch(this.handleError); 
    } 
+0

非常感謝它真的很好 – Hussain