0
votes

I don't know why *ngfor gives me this error, if when I consume the API by console.log it gives me the result but I can't show it on the screen.

"here the complete error": (Cannot find a different supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.)

this is the method.

export class ProductListComponent implements OnInit {

  product: Array<CreateProductDto>;
    /*{
      id: '1',
      nombre: 'pepsi',
      peso: '12 L',
      precio: '$ 1.20',
      cantidad: '1000'
    },
    {
      id: '2',
      nombre: 'Fiora',
      peso: '1L',
      precio: '$ 2.20',
      cantidad: '3000'
    },
    {
      id: '',
      nombre: 'Coca Cola',
      peso: '14L',
      precio: '$ 0.20',
      cantidad: '2000'
    }*/
  

  constructor(private productServices: ProductService) { }

  ngOnInit(): void {
    this.getProducts()
  }

  getProducts(){
    //console.log(this.productServices.getProducts().subscribe(data => console.log(data)));
    this.productServices.getProducts().subscribe(data => {
      this.product = data
    });
  }
}

and this is my service.

export class ProductService {

  constructor( private htpp: HttpClient) { }

  getProducts(): Observable<CreateProductDto[]>{
    return this.htpp.get<CreateProductDto[]>(PathApiRes.GET_PRODUCTS);
  }


}

help me pls.

1
The data you're getting from the service may not be an array. Log that and check.Arcteezy
Change datatype product: Array<CreateProductDto>; to product: CreateProductDto[];Jp Vinjamoori
I already did it but just like that same errorBrayan Caicedo
@Arcteezy inside the product also comes the authorBrayan Caicedo

1 Answers