I need to set some values dynamically in a URL. The code i have now
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());
}
}
Im trying to set the value like this in url this.URL = "http://payd.azurewebsites.net/api/User/"+localStorage.getItem("paydid")+"/account"
. But this gives me something like this http://payd.azurewebsites.net/api/User/%221%22/account
. In console.log()
it show the correct value of localStorage.getItem("paydid")
. How to do this correctly? Thanks!