Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

222
Vistas
Issue with creating array inside array in angular 8 model

I am trying to create a model named "reportVersion"

This contains an array (ReportCategory) that contains objects collection and two variables one is numeric and another is a string.

I am creating this model just to pass to an API, as a parameter body.

Since I have not created a model in the submission form, in the same format as like needs to be passed as a parameter to an API. I need to do fetch values from form Model and push it to reportVersion. Further, I will pass reportVersion to the API as a parameter to call the api.

Currently, I facing issues while building reportVersion. I have put the code below in stackblitz.

I don't understand why console.log(model) is not printing to console. Please help.

  this.reportCategory.push({ categoryName: 'demo1', weightage: 10 });

    this.reportCategory.push({ categoryName: 'demo2', weightage: 20 });

    this.reportCategory.push({ categoryName: 'demo3', weightage: 30 });

    this.reportCategory.forEach((element) => {
      this.reportVersion['categories'].push({
        categoryName: element.categoryName,
        weightage: element.weightage,
      });
    });
    console.log('this is final output');
    console.log(this.reportCategory);

https://stackblitz.com/edit/angular-ivy-vu99yk?file=src/app/hello.component.ts

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You'd need to initialize the reportCategory before using methods on it (like push).

this.reportCategory = []; // Added this line
this.reportCategory.push({ categoryName: 'demo1', weightage: 10 });
this.reportCategory.push({ categoryName: 'demo2', weightage: 20 });
this.reportCategory.push({ categoryName: 'demo3', weightage: 30 });

It worked in the StackBlitz in my side :)

// Dylan

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda