2016-09-23 54 views
0

參數我想與Angular2 HTTP和參數 「searchId」 調用REST服務GET方法與URL裏面是這樣的:Angular2 HTTP GET內部URL

http://localhost:8080/services/name/:searchId/documents/ 

在AngularJS這是很簡單的:

 getDataResource(): ng.resource.IResourceClass<IEntityResource> { 
     console.log("REST CALL"); 
     return this.$resource("http://localhost:8080/services/name/:searchId/documents/", {searchId: "12345678"}, { 
      'query': { 
       method: 'GET', 
       isArray: false 
      } 
     }); 
    } 

您能否提出一個解決方案?

回答

0

做到這一點的唯一方法是不幸簡單級聯:對Http Client documentation

getData(searchId:number):Observable<any>{ 
    return this.http.get(http://localhost:8080/services/name/"+searchId.toString()+"/documents/"; 
} 

更多信息。

0

你可以通過模板字符串插值來實現: 使用back tick來實現它。所以不是""使用和``而不是:searchId使用$searchId

return this.$resource(

`http://localhost:8080/services/name/${searchId} /documents/` 

) 
.someMethod(); 

更多信息看here

+0

這不是有效的語法。它應該是字符串內的'$ {searchId}'。 – WiredPrairie

+0

@WiredPrairie感謝您指出。更正了錯字。 – candidJ