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

167
Views
los datos de propiedad de tipo Object no se pueden leer con ngFor

Angualr no reconoce los datos de propiedad (datos ficticios de una API), aparece el siguiente error: la propiedad 'datos' no existe en el tipo 'Objeto'

Intenté eliminar la propiedad de datos y simplemente usé "permitir usuario de usuarios", pero me da el siguiente error: el tipo 'Objeto' no se puede asignar al tipo 'NgIterable | nulo | indefinido'

mi componente HTML

 <h1>Home</h1> <ul *ngIf="users"> <li value="user" *ngFor="let user of users.data"> <img [src]="user.avatar"> <p>{{ user.first_name }} {{ user.last_name }}</p> </li> </ul>

el componente ts:

 import { Component, OnInit } from '@angular/core'; import { DataService } from '../data.service'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.scss'] }) export class HomeComponent implements OnInit { users: Object; constructor(private data: DataService) { } ngOnInit() { this.data.getUsers().subscribe(data => { this.users = data console.log(this.users) }) } }

el componente ts del servicio de datos:

 import { Injectable } from '@angular/core'; import { HttpClient, HttpClientModule } from '@angular/common/http'; @Injectable({ providedIn: 'root' }) export class DataService { constructor(public http: HttpClient) { } getUsers() { return this.http.get('https://reqres.in/api/users') } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simplemente realice los siguientes cambios en su componente ts para compilar con éxito

usuarios: cualquiera;

O

cree la interfaz como la respuesta de muestra.

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!