Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Cómo establecer el valor del modelo en angular

Estoy tratando de enviar un modelo a mi backend desde mi frontend angular, así es como lo defino en la clase que quiero usar:

 documentsArray : DocumentModel

Ahora tengo este método:

 uploadFile(files: FileList | null): void { if(files){ const file = files.item(0) const reader = new FileReader() reader.readAsDataURL(file) reader.onload = () => { this.documentsArray.filename = file.name, this.api.saveDocument({body: this.documentsArray }).subscribe({ next: data => console.log(data), error: error => console.log("your error: " + error) }) console.log(this.documentsArray[0]) console.log(JSON.stringify(this.documentsArray)) } } }

Pero luego trato de configurar esta parte:

 this.documentsArray.filename = file.name,

Estoy teniendo el siguiente error:

 TypeError: Cannot set properties of undefined (setting 'filename')

El modelo solo tiene cuerdas. Alguien podría decirme mi error.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Primero: debe aclarar si documentsArray es realmente una matriz.

En caso afirmativo, debe especificar el índice en la línea:

 this.documentsArray.filename = file.name,

De la siguiente manera:

 this.documentsArray[0].filename = file.name,

Supongo que quieres establecer el nombre del primer elemento.

Si no, muestre el archivo completo en un editor de código en línea, como CodePen o StackBlitz y comparta el enlace aquí.

about 4 years ago · Juan Pablo Isaza Report

0

DocumentArray no está definido. Por lo tanto, no puede acceder a undefined.filename; tienes que declararlo como documentsArray = {};

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!