0

I have a controller that is consuming url parameters in the form /project/{id}. Hoowever, my angular2 provider creates calls in the following form: /project?id=xxxx. How can I tell angular to call the service with the url format it is waiting for? My angular provider method:

    let params: URLSearchParams = new URLSearchParams();
    params.set('id', id);
    let requestOptions = new RequestOptions();
    requestOptions.search = params;
    return new Promise<Project>((resolve) =>
        this.http.get('/api/Project', requestOptions).subscribe(result => {
            resolve(result.json());
        })
    ); 
Jota.Toledo
  • 27,293
  • 11
  • 59
  • 73
Perrier
  • 2,753
  • 5
  • 33
  • 53
  • 1
    If you have a path parameter, why are you explicitly providing it as a query parameter? Don't you just want `this.http.get(\`/api/Project/${id}\`)...`? Also note that `Observable`s have a [`toPromise` method](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/topromise.md) (or you could *actually use observables*). – jonrsharpe Jun 11 '17 at 09:26
  • Stupid me, thanks both of you. – Perrier Jun 11 '17 at 09:41

0 Answers0