0

I use angular 11.1.2 in my project.

I try to store number ids in an array of number :

let list: number[] = [];

dtInstance.rows({selected: true}).every((item) => {
  list.push(dtInstance.row(item).data()[0]);
});

this.dService.renewDossiers(list,form.value['date']).then(
  () => {
    this.refreshDossiers();
  }
);

And then send it via HTTP POST :

renewDossiers(dossiers:number[], date:Date): Promise<any> {
    return this.httpClient.post(environment.API_URL+'/dossier/renouvellement',{dossiers:dossiers,date:date}).toPromise();
}

But the data sent in the post request for 'dossiers' is a string array :

{dossiers: ["3","4"], date: "2022-01-01"}

I don't understand why dossiers contain text values while I sent a number[] type in post params. It sould send :

{dossiers: [3,4], date: "2022-01-01"}

Can someone explain me what is wrong ?

2
  • what's the difference? keep in mind everything in an http request is text. there are no other data types in http. Commented Mar 16, 2021 at 15:57
  • Yes but there is type in JSON and my Spring backend expects Long[] type, but here angular provides String[] Commented Mar 17, 2021 at 10:44

1 Answer 1

0

Typecast before pushing into the list.

Final outcome:

dtInstance.rows({selected: true}).every((item) => {
  list.push(+(dtInstance.row(item).data()[0]));
});

Added extra () brackets for safety.

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.