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

241
Views
La respuesta JSON está en la matriz pero aún arroja un error "NgFor solo admite el enlace a iterables como matrices"

Archivo mecanografiado

 export class CompanyComponent { apiService : APIService; data : any; private companyUrl = 'http://localhost:4000/api/company/'; constructor(apiService : APIService) { this.apiService = apiService; this.getCompanies(this.companyUrl); } getCompanies(url: any){ this.data = this.apiService.GET(url).map((response :Response)=> response.json()).subscribe((response)=>{ this.data = response; console.log(this.data); }) }

Matriz de respuesta

 [ {"_id":"58f61a132d44240d085ca2fa","comapny_name":"Burslem Spice","__v":1,"categories":["58f643382d44240d085ca2fb"]},<br> {"_id":"590487964a45c56c0fa2911a","comapny_name":"Tiger Bite","categories":[]} ]

archivo HTML

 <div class="media"> <div class="media-left" > <li class="media" *ngFor = "let comp of data" > <label>{{comp}}</label> </li> </div> </div>

La respuesta anterior todavía está en la matriz, pero aparece este error:

ERROR causado por: No se puede encontrar un objeto de soporte diferente '[objeto Objeto]' de tipo 'objeto'. NgFor solo admite el enlace a Iterables como Arrays.

El objeto es una matriz

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

data : any; dice que los datos pueden ser cualquier cosa, pero *ngFor solo acepta Iterables. Cámbielo a array Debido a que está cargando asíncrono, cuando se procesa dom por primera vez, data no estarán definidos y, por lo tanto, angular se quejará.

 export class CompanyComponent { apiService : APIService; data : Array; // or array private companyUrl = 'http://localhost:4000/api/company/'; constructor(apiService : APIService) { this.apiService = apiService; this.getCompanies(this.companyUrl); this.data = [] } getCompanies(url: any){ this.apiService.GET(url).map((response :Response)=> response.json()).subscribe((response)=>{ this.data = response; console.log(this.data); }) }

HTML

 <div class="media"> <div class="media-left" > <li class="media" *ngFor = "let comp of data" > <label> {{comp.company_name}}</label> </li> </div> </div>
over 4 years ago · Santiago Trujillo 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!