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

109
Views
Cómo filtrar una matriz múltiple en un objeto y luego mostrar
const data = { test1: [ {error: ''}, {error: ''}, ], test2: [ {error: ''}, {error: 'theres an error in this field'}, {error: 'theres an error here'}, ], test3: [ {error: ''}, {error: 'theres an error'}, {error: 'theres an error here'}, ] };

¿Cómo filtrar datos con un valor de error y mostrarlos?

 const test1 = data.test1.filter(x => x.error !== ''); const test2 = data.test2.filter(x => x.error !== ''); const test3 = data.test3.filter(x => x.error !== ''); <div> <div *ngFor="let test of test1"> {{test.error}} </div> <div *ngFor="let test of test2"> {{test.error}} </div> <div *ngFor="let test of test3"> {{test.error}} </div> </div>

No estoy seguro de que esta sea la forma correcta.

Lo que estoy tratando de hacer es mostrar todos los errores enumerados sin un espacio como este

 theres an error in this field theres an error here theres an error theres an error here
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Dado que está utilizando Angular y, por lo tanto, Typescript, debe escribir sus variables. .some() devuelve un valor booleano, no una matriz, por lo que const test1 debería ser const test1:boolean . Y ahora ves que no puedes hacer *ngFor="let test of test1" en un booleano.

Reemplace .some con .filter , que devuelve un Array, y debería estar bien.

 const test1: {error:string}[] = data.test1.filter(x => x.error !== '');
about 4 years ago · Juan Pablo Isaza Report

0

Puede extraer todos los errores de los datos usando:

 interface ErrorResponse { error?: string; } const errors: ErrorResponse[] = Object.values(data).flat().filter(row => row.error);

y luego mostrarlos usando:

 <div *ngFor="let response of errors"> {{response.error}} </div>

Referencias: .filter() , .flat() .

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!