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
  • 25,115
  • 9
  • 55
  • 68
Perrier
  • 2,509
  • 5
  • 30
  • 51
  • 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