2

I am using ASP.NET Core and AngularJS 2. There is a problem with http query parameter. No matter what I try, parameter 'quarter' is not passed to controller. Anyone have idea what ma I missing here ?

getBookingsBySaleUnit() {
    let params: URLSearchParams = new URLSearchParams();
    params.set('quarter', '1');
    let requestOptions = new RequestOptions();
    requestOptions.search = params; 

    this.http.get('/api/method', requestOptions).subscribe(result => {
            this.sales = result.json();
        }
      );
  }

2 Answers 2

1

This works for me:

    let params: URLSearchParams = new URLSearchParams();
    params.set('quarter', 1);
    this.http.get('Result/Delete', { search: params })
       .subscribe([...])
Sign up to request clarification or add additional context in comments.

1 Comment

You are right BUT can't believe how simple it was. Actually I was calling controller so ALL I have to do is append it to the URL http.get('/api/method/' + this.quarter) :(
0

You missed to pass the parameter. Try the code below which includes parameter in the URL.

getBookingsBySaleUnit() {
    let params: URLSearchParams = new URLSearchParams();
    params.append('quarter', '1');
    let requestOptions = new RequestOptions();
    requestOptions.headers.set('Content-Type', 'application/x-www-form-urlencoded');
    this.http.get('/api/method?'+params.toString(), requestOptions).subscribe(result => {
        this.sales = result.json();
    });
}

Comments

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.