在angular2中如何将id值分配给url

时间:2017-05-09 12:16:26

标签: angular2-services

这里我写了angular2 url部分为

  onselect(StateId: Country) {
        var GetstateValue = this.http.post("http://localhost:34339/Home/GetStateById/",+StateId)
 GetstateValue.subscribe(res => this.Success)

但它不是Binding StateId值(这里的id值是来的)

1 个答案:

答案 0 :(得分:1)

Angular GET和POST

获取方法:



 onselect(StateId: Country) {
        var GetstateValue = this.http.get("http://localhost:34339/Home/GetStateById/"+StateId)
 GetstateValue.subscribe(res =>{ this.Success=res; console.log(res);)




发布方法



 onselect(StateId: Country) {
  const header = new Headers();
      header.append('Content-Type', 'application/x-www-form-urlencoded');
      let data = StateId;
        var GetstateValue = this.http.post("http://localhost:34339/Home/GetStateById/", data, {headers: header}).map(res=>res.json());
 GetstateValue.subscribe(res => this.Success);