我在angular2服务中有一个函数,它传递一个id以附加到Http get请求的基本URL但是它不起作用。当我输入确切的字符串时,它可以很好地获取数据,但它不会让我附加变量,如
' http://localhost:3000/project/allTask/' + project_id
dec esi
更新
我相信未定义时传递的project_id。这是我的组件的功能。
getTasks(project_id){
this.loadToken();
let headers = new Headers();
headers.append('Content-Type','application/json');
return this.http.get('http://localhost:3000/project/allTask/5b0919ea256f2e15f8f4364f' , {headers: headers})
.map(res => res.json());
}
答案 0 :(得分:1)
就这样使用它:
getTasks(project_id){
this.loadToken();
let headers = new Headers();
headers.append('Content-Type','application/json');
return this.http.get('http://localhost:3000/project/allTask/' + project_id, {headers: headers})
.map(res => res.json());
}
或
getTasks(project_id){
this.loadToken();
let headers = new Headers();
headers.append('Content-Type','application/json');
return this.http.get(`http://localhost:3000/project/allTask/${project_id}`, {headers: headers})
.map(res => res.json());
}