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

150
Views
¿Cómo mostrar elementos en la página según el valor del campo? Angular

Genero campos con loadFields(). Todos ellos se representan con éxito en html en una fila. Pero necesito que los campos se representen por separado según el grupo. Para poder agruparlos y añadir un encabezado. Intenté hacerlo con *ngIf="item.group === 'group1'" pero no funciona.

Pude excluir un campo antes con *ngIf="item.key !== 'item1'"

 loadFields() { this.fields = { item1: { group: 'group1', title: '', type: 'text', value: 'some value1', validation: [Validators.required] }, item2: { group: 'group1', title: '', type: 'text', value: 'some value2', validation: [Validators.required] }, item3: { group: 'group2', title: '', type: 'text', value: 'some value3', validation: [Validators.required] }, item4: { group: 'group2', title: '', type: 'text', value: 'some value4', validation: [Validators.required] }, } } originalOrder = (a: KeyValue<number, string>, b: KeyValue<number, string>): number => { return 0; }
 <ng-container *ngFor="let item of fields | keyvalue: originalOrder"> <div class="col-lg-12"> <legend class="h6">Group 1</legend> <div class="col-lg-12" *ngIf="item.group === 'group1'"> <app-input-item [complexForm]="langComplexForm" [field]="item.value" ></app-input-item> </div> </div> <div class="col-lg-12"> <legend class="h6">Group 2</legend> <div class="col-lg-12" *ngIf="item.group === 'group2'"> <app-input-item [complexForm]="langComplexForm" [field]="item.value" ></app-input-item> </div> </div> </ng-container>

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

0

puedes usar ngSwitch https://angular.io/api/common/NgSwitch algo como esto:

 <ng-container *ngFor="let item of fields | keyvalue: originalOrder" > <div [ngSwitch]="item.group"> <div class="col-lg-12" *ngSwitchCase="'group1'"> <legend class="h6">Group 1</legend> <div class="col-lg-12"> <app-input-item [complexForm]="langComplexForm" [field]="item.value" ></app-input-item> </div> </div> <div class="col-lg-12" *ngSwitchCase="'group2'"> <legend class="h6">Group 2</legend> <div class="col-lg-12"> <app-input-item [complexForm]="langComplexForm" [field]="item.value" ></app-input-item> </div> </div> </div> </ng-container>
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!