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?
javascript angular typescript angular6
add a comment |
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?
javascript angular typescript angular6
Read the API documentation. It should clarify this issue
– fredrik
Nov 15 '18 at 10:23
add a comment |
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?
javascript angular typescript angular6
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?
javascript angular typescript angular6
javascript angular typescript angular6
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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})}
add a comment |
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});
}
}
add a comment |
Http POST
takes resource URL as a parameter and additional two paramters
- the Data to POST in the body of the request
- 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 );
}
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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})}
add a comment |
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})}
add a comment |
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})}
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})}
answered Nov 15 '18 at 10:48
paresh kalsariyaparesh kalsariya
7317
7317
add a comment |
add a comment |
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});
}
}
add a comment |
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});
}
}
add a comment |
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});
}
}
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});
}
}
edited Nov 15 '18 at 10:33
answered Nov 15 '18 at 10:27
Artyom AmiryanArtyom Amiryan
1,9621214
1,9621214
add a comment |
add a comment |
Http POST
takes resource URL as a parameter and additional two paramters
- the Data to POST in the body of the request
- 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 );
}
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
add a comment |
Http POST
takes resource URL as a parameter and additional two paramters
- the Data to POST in the body of the request
- 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 );
}
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
add a comment |
Http POST
takes resource URL as a parameter and additional two paramters
- the Data to POST in the body of the request
- 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 );
}
Http POST
takes resource URL as a parameter and additional two paramters
- the Data to POST in the body of the request
- 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 );
}
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Read the API documentation. It should clarify this issue
– fredrik
Nov 15 '18 at 10:23