Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
Issue ordering an array with nested objects using ngx-order-pipe

I am facing a problem when wanting to order an array of objects that also have objects inside, I am using [ngx-order-pipe]. I am using Angular 8. I think the problem is wanting to sort an array of objects and access other objects to be able to sort based on keys

The component.html

<table>
    <thead>
        <tr>
            <th></th>
            <th class="sortable">
                <span class="sort" (click)="sort('coln1')">
                    <img src="{{ROOT}}/assets/arrow_off.png"/>
                </span>
                <span style="margin-left: 2%;">Coln1</span>
            </th>
            ...
            <th>&nbsp;</th>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor="let element of supplies | orderBy: orderHeader: false" >
            <td style="width:1%">
                <input name="supplyId" type="hidden" value="2">
            </td>
            <td>{{(element.coln1 != null)?element.coln1 : element.supply.coln1}}</td>
            <td>{{element.supply.coln2}}</td>
            <td>{{element.supply.coln3 }}</td>
            <td>{{element.coln4 != null ? element.coln4 : 1}}</td>
            <td style="width: 1%;"></td>
        </tr>
    </tbody>
</table>

component.ts

export class TableComponent implements OnInit {

  @Input() suministros: any = [];
  @Output() clickEvent = new EventEmitter();
  orderHeader: String = "";
  reverse = true;

  constructor(private orderPipe: OrderPipe) {
    this.ROOT = env.root;
  }

  ngOnInit() {}
   
 
  sort(headerName: String): void {
    this.reverse = !this.reverse;
    this.orderHeader = headerName;
    //this.suministros = this.orderPipe.transform(this.suministros, this.reverse);
  }
  
}

And throws this error:

compiler.js:2420
 Uncaught Error: Template parse errors: The pipe 'orderBy' could not be found 
(</thead> <tbody> <tr *ngFor="let ele[ERROR ->]ment of supplies | orderBy: orderHeader: false")
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Import OrderModule in the module where TableComponent is declared.

Let's say your TableComponent is declared in AppModule, So add OrderModule in the imports array as

import { OrderModule } from 'ngx-order-pipe';

@NgModule({
  imports: [BrowserModule, OrderModule],
  declarations: [AppComponent, TableComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda