我无法从GET
方法中获取任何数据。我有一个名为job.ts
的页面,在该页面中,我正在调用另一个提供程序/服务ts
文件中的方法。
` // This part of the code is from the provider/service .ts file.
getSavedJobList(userId) {
let headers = new HttpHeaders();
headers.append('Content-Type','application/json');
return this.http.get(this.db_url + 'savedjobList/' + userId,{headers: headers})
.subscribe((data: any) => {
console.log(data);
return data
},(err: any) => console.log(err));
}
// this part of the code is from the job.ts file
async getSavedJobs() {
let id = await this.profileId();
this.jobService.getSavedJobList(id).then((list: any) => {
for (let job of list) {
this.savedjobs.push(job);
}
}).catch((err: any) => {
console.log('err in getting the saved jobs '+ err);
});
}
} `
这里没有采取任何行动。
答案 0 :(得分:1)
为什么不将请求返回给job.ts并在此处订阅响应?试试这个:
getSavedJobList(userId) {
let headers = new HttpHeaders();
headers.append('Content-Type','application/json');
return this.http.get(this.db_url + 'savedjobList/' + userId,{headers: headers});
}
在job.ts
async getSavedJobs() {
let id = await this.profileId();
this.jobService.getSavedJobList(id).subscribe((list: any) => {
for (let job of list) {
this.savedjobs.push(job);
}
}).catch((err: any) => {
console.log('err in getting the saved jobs '+ err);
});
}
}