This is the Image of the API request results如何以角度創建HTTP請求並從對象獲取主體?
在這裏,我寫了一個名爲FaqService
使HTTP
請求服務,並呼籲在一個組件,它的服務。
getServers(data: string){
return this.http.get(Staticdata.apiBaseUrl + "/2.2/search/advanced?key="+ Staticdata.key +"&access_token="+ Staticdata.access_token +"&/2.2/search/advanced?order=desc&sort=activity&accepted=True&closed=True&title=" + data + Staticdata.redirectUrl + "&filter="+ Staticdata.filters)
.map(
(response: Response) => {
const items = response.json();
return items;
})
.catch(
(error: Response) => {
return Observable.throw(error);
});
}
}
component.ts
onRecievingResults(value){
console.log(value);
this.router.navigate(['results'], {relativeTo: this.route});
this.faqService.getServers(value)
.subscribe(
(item: any[]) => {
console.log(item);
},
(error) => console.log(error)
);
}
在這裏,在這個HTML模板我如何通過API的結果,並得到身體。
</div>
<div class="entryTitle" *ngFor = "let item of items">
<h1>Search results for :{{ item.body }}</h1>
</div>
</div>
so what問題 –
你到底面臨什麼問題? –