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

191
Vistas
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 Respuestas
Responde la pregunta

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