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

189
Views
Get all attributes from model

I try to list all attibutes from a model class define in my angular app.

Here is an example of my model.

export class BiduleList {
  config: {
    attribute01: string;
    attribute02: number;
  }
  configuration: {
    trululu: {
      attribute03: string;
      attribute04: number;
      attribute05: number;
      attribute06: number;
    }
  }
}

I need to loop over all the attributes to build a form to define the associated data.

So I need to keep the layout, i.e. have the information that attribute03 is contained in trululu itself contained in configuration

Here is an example of what I want to build from this information :

public configurationTrululu: { [key: string]: QuestionBase<any> };

this.configurationTrululu = {
  attribute03: new InputQuestion({
    questionContainerClass: FORM_FIELD_COL_FULL,
    textLabel: "attribute03",
  }),
  attribute04: new InputNumberQuestion({
    questionContainerClass: FORM_FIELD_COL_FULL,
    textLabel: "attribute03",
  }),
  attribute05: new InputNumberQuestion({
    questionContainerClass: FORM_FIELD_COL_FULL,
    textLabel: "attribute03",
  }),
  ...
}

If possible I would like to avoid having to define all attributes in a constructor like this:

constructor() {
  this.config = {
    attribute01 = '',
    attribute01 = 0
  };
}

PS: After a question in comment

when I define a new BiduleList(); like that :

public biduleList: BiduleList = new BiduleList();

biduleList is empty and I can't extract all attribute from him. When I display the result of Object.entries in console :

console.log('biduleList', this.biduleList);
>>> biduleList > BiduleList

console.log('entries', Object.entries(this.biduleList));
>>> entries >Array(0)

PSS: I know that in PHP for example you can use the get_class_vars or get_object_vars function

Here an example : https://onlinephp.io/c/d419d

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

0

You need create an object with values. As you're working with classes you can

export class Fool{
  name:string;
  group:{
    op1:number;
    op2:number;
  }
  schema(){
    const fool=new Fool();
    fool.name='';
    fool.group={op1:2,op2:3}
    return Object.keys(fool)
  }

And use

schema=new Fool().schema();

You can also in constructor of your class create an object with default values

  constructor(){
    this.name='';
    this.group={op1:2,op2:3}
  }

And create an object and iterate over the Object.keys

 fool=new Fool();
 schema=keys(this.fool)
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!