我想通过输入文本来更新服务URL中的2个参数,然后选择
网址:http://localhost/?population/?article=code&year=value
如何通过输入文本来设置代码和值并在Angular 5中选择值
谢谢
答案 0 :(得分:0)
getPopByCY(code: string, value : string): Observable<Article[]> {
//set request params
let params: URLSearchParams = new URLSearchParams();
params.set("article", code);
params.set("year", value);
//params.set("surname", surname); for more params
this.options.search = params;
let url = "http://192.168.1.10:8080/RESTfulArticle/rest/article";
console.log("url: ", url);
return this.httpClient.get(url,this.options)
.map((resp: Response) => resp.json() as Article[])
.catch(this.handleError);
}
private handleError(err) {
console.log(err);
return Observable.throw(err || 'Server error');
}
}
article.component.ts
GetPbyCodeandYears(code : string , value : string) {
this.countriesService.getPopByCY(code,value).subscribe(users => {
this.pops = users as Population[];
console.log(users);
});
我想将参数添加到此链接:http://192.168.1.10:8080/RESTfulArticle/rest/article?country=code&year=value
错误:属性“标题”的类型不兼容。 类型'Headers'不能分配给类型'HttpHeaders | {[header:string]:字符串|串[]; }'。