4

The first block is working as expected

getQuotes(): Observable<Quote[]> {
    return this.http.get(this.url)
        .map((res: Response) => res.json())
        .catch((error: any) => Observable.throw(error.json().error || 'Server error'));
}

Now I am tring to add query params to this.url and the url have not changed

getQuotes2(): Observable<Quote[]> {
    let myParams  = new URLSearchParams();
    myParams.append('author', 'authorName');
    myParams.append('catid', '123');
    let options = new RequestOptions({ params: myParams });

    return this.http.get(this.url, options )
        .map((res: Response) => res.json())
        .catch((error: any) => Observable.throw(error.json().error || 'Server error'));
}

I have checked in devtools. Caching is switched off. I have tried { search: myParams }, with RequestOptions and return this.http.get(this.url, { params: myParams } ) Where I am not looking i see string concatination. These parameters are optinal and I append them on condition.

1 Answer 1

6

Have you imported params ?

import { URLSearchParams } from '@angular/http';
Sign up to request clarification or add additional context in comments.

2 Comments

I have checked, yes it works. The absent of import do not cause error messages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.