0

I am trying to pass a value by current url using POST http method in angular 2 but I am getting error.

TS:

  let urlSearchParams = new URLSearchParams();
  urlSearchParams.append('arrydetails', this.registerForm.value);

  this.http.post('currenturl', urlSearchParams).subscribe(
  data => {
    alert('ok');
  },
  error => {
    console.log(JSON.stringify(error.json()));
  }
)
3
  • 1
    Can you share the error? Commented Sep 19, 2018 at 22:23
  • Are you using http request or httpClient? Commented Sep 20, 2018 at 0:17
  • can you create a stackbliz? Commented Sep 20, 2018 at 1:58

1 Answer 1

2

Angular's documentation on http requests:

https://angular.io/guide/http#making-a-post-request

Here you will be able to find out to properly make POST, DELETE, PUT requests and how to to pass the value of form fields into the request.

To provide a snippet of what the Angular doc suggests

addHero (hero: Hero): Observable<Hero> {
       return this.http.post<Hero>(this.heroesUrl, hero, httpOptions)
    .pipe(
      catchError(this.handleError('addHero', hero))
    );
}

Now the solution

In the example where you would want to place your data to be posted is where 'hero' can be found and in your case it seems you want it to be 'this.registerForm.value'? The way your currently doing the post your not passing any data to be posted.

Sign up to request clarification or add additional context in comments.

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.