动态设置URL中的参数Angularjs2

时间:2016-10-19 14:09:37

标签: angular

我需要在URL中动态设置一些值。 我现在的代码

export class AccountService {

private accounts;
private URL="";

constructor(private http: Http) {
  this.URL =   "http://payd.azurewebsites.net/api/User/"+localStorage.getItem("paydid")+"/accou nt";
  console.log(localStorage.getItem("paydid"));
}

httpGet(): Observable<Account> {
  var headers = new Headers();
  headers.append('Authorization', 'bearer ' + localStorage.getItem('token'));
  headers.append('Content-Type', 'application/x-www-form-urlencoded');

  return this.http.get(this.URL, {
    headers: headers
  }).catch((error: any, caught: Observable<any>) => {
      return Observable.throw(error);
    })
  .map((response: Response) => response.json());
  }
}

我试图在网址this.URL = "http://payd.azurewebsites.net/api/User/"+localStorage.getItem("paydid")+"/account"中设置这样的值。但这给了我类似http://payd.azurewebsites.net/api/User/%221%22/account的东西。在console.log()中,它显示localStorage.getItem("paydid")的正确值。怎么做到这一点?谢谢!

0 个答案:

没有答案