Expected 2-3 Arguments But Got 4 In Angular While Performing POST Operation?
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:
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 :
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?
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})}
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM