Expected 2-3 arguments but got 4 in angular while performing POST operation?












-1















I have a form and when i click the submit button onSubmit() function is called and here i have printed in console all the datas that are needed to be passed through component class like this:



onSubmit() {
this.submitted = true;
console.log("entered in submiteed");
console.log(this.selectedTable);
console.log(this.documents);
console.log(this.empList);

this.letter.inOut="AnnexOne";
this.letter.letterFile=null;
this.letter.representativeName=null;
this.letter.assessmentNo=0;
this.letter.letterIssuedSubBy=null;
console.log(this.letter);
this.letterService.saveThree(this.selectedTable,this.documents,this.empList).subscribe(data => console.log(data), error => console.log(error));
}


The JSON data that is printed in console is like:



enter image description here



I tried to send the three parameters from here saveThree(this.selectedTable,this.documents,this.empList)



and send it to service class,so i need to perform post operation so i tried :



export class LetterService {

private baseUrl = 'http://localhost:8080/api/letter';
private letter = new Letter();

constructor(private http: HttpClient) { }


saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
return this.http.post(`${this.baseUrl}` + `/create`, selectedTable,documents,empList);
}

}


In this class also i have used three parameters to receive but the error is :



enter image description here



I need to pass these three parameters from service class to backend but Why it is me showing me such mismatch error though there are equal number of parameters?










share|improve this question























  • Read the API documentation. It should clarify this issue

    – fredrik
    Nov 15 '18 at 10:23


















-1















I have a form and when i click the submit button onSubmit() function is called and here i have printed in console all the datas that are needed to be passed through component class like this:



onSubmit() {
this.submitted = true;
console.log("entered in submiteed");
console.log(this.selectedTable);
console.log(this.documents);
console.log(this.empList);

this.letter.inOut="AnnexOne";
this.letter.letterFile=null;
this.letter.representativeName=null;
this.letter.assessmentNo=0;
this.letter.letterIssuedSubBy=null;
console.log(this.letter);
this.letterService.saveThree(this.selectedTable,this.documents,this.empList).subscribe(data => console.log(data), error => console.log(error));
}


The JSON data that is printed in console is like:



enter image description here



I tried to send the three parameters from here saveThree(this.selectedTable,this.documents,this.empList)



and send it to service class,so i need to perform post operation so i tried :



export class LetterService {

private baseUrl = 'http://localhost:8080/api/letter';
private letter = new Letter();

constructor(private http: HttpClient) { }


saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
return this.http.post(`${this.baseUrl}` + `/create`, selectedTable,documents,empList);
}

}


In this class also i have used three parameters to receive but the error is :



enter image description here



I need to pass these three parameters from service class to backend but Why it is me showing me such mismatch error though there are equal number of parameters?










share|improve this question























  • Read the API documentation. It should clarify this issue

    – fredrik
    Nov 15 '18 at 10:23
















-1












-1








-1








I have a form and when i click the submit button onSubmit() function is called and here i have printed in console all the datas that are needed to be passed through component class like this:



onSubmit() {
this.submitted = true;
console.log("entered in submiteed");
console.log(this.selectedTable);
console.log(this.documents);
console.log(this.empList);

this.letter.inOut="AnnexOne";
this.letter.letterFile=null;
this.letter.representativeName=null;
this.letter.assessmentNo=0;
this.letter.letterIssuedSubBy=null;
console.log(this.letter);
this.letterService.saveThree(this.selectedTable,this.documents,this.empList).subscribe(data => console.log(data), error => console.log(error));
}


The JSON data that is printed in console is like:



enter image description here



I tried to send the three parameters from here saveThree(this.selectedTable,this.documents,this.empList)



and send it to service class,so i need to perform post operation so i tried :



export class LetterService {

private baseUrl = 'http://localhost:8080/api/letter';
private letter = new Letter();

constructor(private http: HttpClient) { }


saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
return this.http.post(`${this.baseUrl}` + `/create`, selectedTable,documents,empList);
}

}


In this class also i have used three parameters to receive but the error is :



enter image description here



I need to pass these three parameters from service class to backend but Why it is me showing me such mismatch error though there are equal number of parameters?










share|improve this question














I have a form and when i click the submit button onSubmit() function is called and here i have printed in console all the datas that are needed to be passed through component class like this:



onSubmit() {
this.submitted = true;
console.log("entered in submiteed");
console.log(this.selectedTable);
console.log(this.documents);
console.log(this.empList);

this.letter.inOut="AnnexOne";
this.letter.letterFile=null;
this.letter.representativeName=null;
this.letter.assessmentNo=0;
this.letter.letterIssuedSubBy=null;
console.log(this.letter);
this.letterService.saveThree(this.selectedTable,this.documents,this.empList).subscribe(data => console.log(data), error => console.log(error));
}


The JSON data that is printed in console is like:



enter image description here



I tried to send the three parameters from here saveThree(this.selectedTable,this.documents,this.empList)



and send it to service class,so i need to perform post operation so i tried :



export class LetterService {

private baseUrl = 'http://localhost:8080/api/letter';
private letter = new Letter();

constructor(private http: HttpClient) { }


saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
return this.http.post(`${this.baseUrl}` + `/create`, selectedTable,documents,empList);
}

}


In this class also i have used three parameters to receive but the error is :



enter image description here



I need to pass these three parameters from service class to backend but Why it is me showing me such mismatch error though there are equal number of parameters?







javascript angular typescript angular6






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 10:18









ashwin karkiashwin karki

23211




23211













  • Read the API documentation. It should clarify this issue

    – fredrik
    Nov 15 '18 at 10:23





















  • Read the API documentation. It should clarify this issue

    – fredrik
    Nov 15 '18 at 10:23



















Read the API documentation. It should clarify this issue

– fredrik
Nov 15 '18 at 10:23







Read the API documentation. It should clarify this issue

– fredrik
Nov 15 '18 at 10:23














3 Answers
3






active

oldest

votes


















1














Because POST request has three parameters(first is URL,second is DATA that you need to pass and third is optional which is header information).If you want to pass more than one data then you need to like below.



return this.http.post(`${this.baseUrl}` + `/create`, {selectedTable,documents,empList})}





share|improve this answer































    1














    because post request takes 3 parameters(URL, DATA object that you need to send, and HttpOptions object if you need to send additional options),
    you are sending here selectedTable as Data object, documents as HttpOptions object, and empList just as 4th argument, to solve this just add that 3 objects in one and send as one object (as second parameter DATA)



      export class LetterService {

    private baseUrl = 'http://localhost:8080/api/letter';
    private letter = new Letter();

    constructor(private http: HttpClient) { }


    saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
    return this.http.post(`${this.baseUrl}` + `/create`, {selectedTable: selectedTable,documents: documents, empList: empList});
    }

    }





    share|improve this answer

































      1














      Http POST takes resource URL as a parameter and additional two paramters




      1. the Data to POST in the body of the request

      2. the method HttpOptions (if any)


      For example :



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


      in your .ts



      saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
      let _data = {
      "selectedTable" : selectedTable,
      "documents" : documents,
      "empList" : empList
      }
      return this.http.post(`${this.baseUrl}` + `/create`, _data );
      }





      share|improve this answer


























      • where i need to add this please illustrate me

        – ashwin karki
        Nov 15 '18 at 11:03











      • @ashwinkarki You should wrap all your data into an object and use the same at your backend to retrieve the data.

        – Sarthak Aggarwal
        Nov 15 '18 at 12:06











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317158%2fexpected-2-3-arguments-but-got-4-in-angular-while-performing-post-operation%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Because POST request has three parameters(first is URL,second is DATA that you need to pass and third is optional which is header information).If you want to pass more than one data then you need to like below.



      return this.http.post(`${this.baseUrl}` + `/create`, {selectedTable,documents,empList})}





      share|improve this answer




























        1














        Because POST request has three parameters(first is URL,second is DATA that you need to pass and third is optional which is header information).If you want to pass more than one data then you need to like below.



        return this.http.post(`${this.baseUrl}` + `/create`, {selectedTable,documents,empList})}





        share|improve this answer


























          1












          1








          1







          Because POST request has three parameters(first is URL,second is DATA that you need to pass and third is optional which is header information).If you want to pass more than one data then you need to like below.



          return this.http.post(`${this.baseUrl}` + `/create`, {selectedTable,documents,empList})}





          share|improve this answer













          Because POST request has three parameters(first is URL,second is DATA that you need to pass and third is optional which is header information).If you want to pass more than one data then you need to like below.



          return this.http.post(`${this.baseUrl}` + `/create`, {selectedTable,documents,empList})}






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 10:48









          paresh kalsariyaparesh kalsariya

          7317




          7317

























              1














              because post request takes 3 parameters(URL, DATA object that you need to send, and HttpOptions object if you need to send additional options),
              you are sending here selectedTable as Data object, documents as HttpOptions object, and empList just as 4th argument, to solve this just add that 3 objects in one and send as one object (as second parameter DATA)



                export class LetterService {

              private baseUrl = 'http://localhost:8080/api/letter';
              private letter = new Letter();

              constructor(private http: HttpClient) { }


              saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
              return this.http.post(`${this.baseUrl}` + `/create`, {selectedTable: selectedTable,documents: documents, empList: empList});
              }

              }





              share|improve this answer






























                1














                because post request takes 3 parameters(URL, DATA object that you need to send, and HttpOptions object if you need to send additional options),
                you are sending here selectedTable as Data object, documents as HttpOptions object, and empList just as 4th argument, to solve this just add that 3 objects in one and send as one object (as second parameter DATA)



                  export class LetterService {

                private baseUrl = 'http://localhost:8080/api/letter';
                private letter = new Letter();

                constructor(private http: HttpClient) { }


                saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
                return this.http.post(`${this.baseUrl}` + `/create`, {selectedTable: selectedTable,documents: documents, empList: empList});
                }

                }





                share|improve this answer




























                  1












                  1








                  1







                  because post request takes 3 parameters(URL, DATA object that you need to send, and HttpOptions object if you need to send additional options),
                  you are sending here selectedTable as Data object, documents as HttpOptions object, and empList just as 4th argument, to solve this just add that 3 objects in one and send as one object (as second parameter DATA)



                    export class LetterService {

                  private baseUrl = 'http://localhost:8080/api/letter';
                  private letter = new Letter();

                  constructor(private http: HttpClient) { }


                  saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
                  return this.http.post(`${this.baseUrl}` + `/create`, {selectedTable: selectedTable,documents: documents, empList: empList});
                  }

                  }





                  share|improve this answer















                  because post request takes 3 parameters(URL, DATA object that you need to send, and HttpOptions object if you need to send additional options),
                  you are sending here selectedTable as Data object, documents as HttpOptions object, and empList just as 4th argument, to solve this just add that 3 objects in one and send as one object (as second parameter DATA)



                    export class LetterService {

                  private baseUrl = 'http://localhost:8080/api/letter';
                  private letter = new Letter();

                  constructor(private http: HttpClient) { }


                  saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
                  return this.http.post(`${this.baseUrl}` + `/create`, {selectedTable: selectedTable,documents: documents, empList: empList});
                  }

                  }






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 15 '18 at 10:33

























                  answered Nov 15 '18 at 10:27









                  Artyom AmiryanArtyom Amiryan

                  1,9621214




                  1,9621214























                      1














                      Http POST takes resource URL as a parameter and additional two paramters




                      1. the Data to POST in the body of the request

                      2. the method HttpOptions (if any)


                      For example :



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


                      in your .ts



                      saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
                      let _data = {
                      "selectedTable" : selectedTable,
                      "documents" : documents,
                      "empList" : empList
                      }
                      return this.http.post(`${this.baseUrl}` + `/create`, _data );
                      }





                      share|improve this answer


























                      • where i need to add this please illustrate me

                        – ashwin karki
                        Nov 15 '18 at 11:03











                      • @ashwinkarki You should wrap all your data into an object and use the same at your backend to retrieve the data.

                        – Sarthak Aggarwal
                        Nov 15 '18 at 12:06
















                      1














                      Http POST takes resource URL as a parameter and additional two paramters




                      1. the Data to POST in the body of the request

                      2. the method HttpOptions (if any)


                      For example :



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


                      in your .ts



                      saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
                      let _data = {
                      "selectedTable" : selectedTable,
                      "documents" : documents,
                      "empList" : empList
                      }
                      return this.http.post(`${this.baseUrl}` + `/create`, _data );
                      }





                      share|improve this answer


























                      • where i need to add this please illustrate me

                        – ashwin karki
                        Nov 15 '18 at 11:03











                      • @ashwinkarki You should wrap all your data into an object and use the same at your backend to retrieve the data.

                        – Sarthak Aggarwal
                        Nov 15 '18 at 12:06














                      1












                      1








                      1







                      Http POST takes resource URL as a parameter and additional two paramters




                      1. the Data to POST in the body of the request

                      2. the method HttpOptions (if any)


                      For example :



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


                      in your .ts



                      saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
                      let _data = {
                      "selectedTable" : selectedTable,
                      "documents" : documents,
                      "empList" : empList
                      }
                      return this.http.post(`${this.baseUrl}` + `/create`, _data );
                      }





                      share|improve this answer















                      Http POST takes resource URL as a parameter and additional two paramters




                      1. the Data to POST in the body of the request

                      2. the method HttpOptions (if any)


                      For example :



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


                      in your .ts



                      saveThree(selectedTable: any,documents: any,empList: any): Observable<Object> {
                      let _data = {
                      "selectedTable" : selectedTable,
                      "documents" : documents,
                      "empList" : empList
                      }
                      return this.http.post(`${this.baseUrl}` + `/create`, _data );
                      }






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 15 '18 at 12:08

























                      answered Nov 15 '18 at 10:21









                      Sarthak AggarwalSarthak Aggarwal

                      65817




                      65817













                      • where i need to add this please illustrate me

                        – ashwin karki
                        Nov 15 '18 at 11:03











                      • @ashwinkarki You should wrap all your data into an object and use the same at your backend to retrieve the data.

                        – Sarthak Aggarwal
                        Nov 15 '18 at 12:06



















                      • where i need to add this please illustrate me

                        – ashwin karki
                        Nov 15 '18 at 11:03











                      • @ashwinkarki You should wrap all your data into an object and use the same at your backend to retrieve the data.

                        – Sarthak Aggarwal
                        Nov 15 '18 at 12:06

















                      where i need to add this please illustrate me

                      – ashwin karki
                      Nov 15 '18 at 11:03





                      where i need to add this please illustrate me

                      – ashwin karki
                      Nov 15 '18 at 11:03













                      @ashwinkarki You should wrap all your data into an object and use the same at your backend to retrieve the data.

                      – Sarthak Aggarwal
                      Nov 15 '18 at 12:06





                      @ashwinkarki You should wrap all your data into an object and use the same at your backend to retrieve the data.

                      – Sarthak Aggarwal
                      Nov 15 '18 at 12:06


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317158%2fexpected-2-3-arguments-but-got-4-in-angular-while-performing-post-operation%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Florida Star v. B. J. F.

                      Danny Elfman

                      Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues