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

221
Views
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 answers
Answer question

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 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!