文件結構後PARAMS,並使http
請求,我得到的結果,如果我再次搜索我無法得到結果。搜索一次,不能再次搜索
faq.component.ts
onRecievingResults() {
this.router.navigate(['results', this.inputValue], {relativeTo: this.route});
}
搜索results.component.ts
export class SearchResultsComponent implements OnInit {
data: any[];
item: any[];
inputValue;
constructor(private faqService: FaqService,private route: ActivatedRoute,) {
}
ngOnInit() {
this.route.params.subscribe(
(params : Params) => {
this.inputValue = params["inputValue"];
}
);
this.faqService.getServers(this.inputValue)
.subscribe(
(data) => {
this.item = data.items;
},
(error) => console.log(error)
);
}
}
faq.service.ts
getServers(inputValue) {
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=" + inputValue + Staticdata.redirectUrl + "&filter="+ Staticdata.filters)
.map(
(response: Response) => {
const items = response.json();
return items;
},
)
.catch(
(error: Response) => {
return Observable.throw(error);
}
);
}
的組件將初始化一次這一切關於搜索欄。 – Hoyen
在你的formcontrol上綁定'valueChanges' –
如何重複它一遍又一遍,以便我可以搜索不同的值? @Hoyen –