-1

Model classes:

import { Employee } from "./employee";

export interface Company {
  id: number;
  companyName: string;
  dateOfEstablishment: Date;
  companyInformation: string;
  companyLogo: string;
  employees: Employee[];
}

import { Company } from "./company";
import { EmployeeAddresses } from "./employeeAddresses";
import { EmployeeBankData } from "./employeeBankData";
import { EmployeeContacts } from "./employeeContacts";
import { EmployeeContracts } from "./employeeContracts";
import { EmployeeDependents } from "./employeeDependents";
import { EmployeeIdentityDocuments } from "./employeeIdentityDocuments";
import { EmployeePersonalDatas } from "./employeePersonalDatas";

export interface Employee {
  id: number;
  employeePersonalDatas: EmployeePersonalDatas;
  employeeAddresses: EmployeeAddresses[];
  employeeContacts: EmployeeContacts[];
  employeeIdentityDocuments: EmployeeIdentityDocuments[];
  employeeBankData: EmployeeBankData[];
  employeeDependents: EmployeeDependents;
  employeeContracts: EmployeeContracts[];
  employeeCompany: Company;
}

 public companies: Company[] = [];

  public constructor(private companyService: CompanyService) { }

  public ngOnInit(): void {
    this.getCompanies();
  }

  public getCompanies() {
    this.companyService.getCompanies().subscribe((companies) => {
      this.companies = companies;
    })
  }

This is my company-list.compnonent

private baseUrl: string = `${environment.baseUrl}`;

  public constructor(private httpClient: HttpClient) {}

  public getCompanies(): Observable<Company[]> {
    return this.httpClient.get<Company[]>(this.baseUrl);
  }

This is my service

<div *ngFor="let company of companies">
    <app-company-card [company]="company" (selectionChange)="onItemSelected()"></app-company-card>
</div>

And this is my html

Can someone help me? Is for my internship and I cant figure out why I get this error : Error trying to diff '[object Object]'. Only arrays and iterables are allowed

Paul Ivan
  • 9
  • 1
  • 2
  • 3
  • before `this.companies = companies` add `console.log(companies)` then check, is `companies` really array? – Muhammet Can TONBUL Oct 14 '21 at 10:05
  • Yes, that's correct. You can only iterate arrays and other iterables. A basic `object` is not iterable. You can't iterate objects in JavaScript. – jabaa Oct 14 '21 at 10:13
  • Check my answer here https://stackoverflow.com/a/62382073/5536695 – YogendraR Oct 14 '21 at 10:15
  • If I cant iterate objects, what can I do then? I must display the companies – Paul Ivan Oct 14 '21 at 16:16
  • Where are the companies stored? What's the data structure? The type of `companies` is `Company[]`. That looks correct. Perhaps the actual data isn't an array. – jabaa Oct 14 '21 at 16:29

1 Answers1

0
{$id: '1', $values: Array(10)}$id: "1"$values: Array(10)0: {$id: '2', id: 3, companyName: 'Company112', dateOfEstablishment: '0001-01-01T00:00:00', companyInformation: null, …}1: {$id: '14', id: 16, companyName: 'companieeeee', dateOfEstablishment: '0001-01-01T00:00:00', companyInformation: null, …}2: {$id: '16', id: 17, companyName: 'companiaSDFSSFFFSFFS', dateOfEstablishment: '0001-01-01T00:00:00', companyInformation: null, …}3: {$id: '20', id: 18, companyName: 'MyCompany', dateOfEstablishment: '0001-01-01T00:00:00', companyInformation: 'Nice Company', …}4: {$id: '23', id: 19, companyName: 'create', dateOfEstablishment: '0001-01-01T00:00:00', companyInformation: null, …}5: {$id: '25', id: 20, companyName: 'create', dateOfEstablishment: '0001-01-01T00:00:00', companyInformation: null, …}6: {$id: '27', id: 21, companyName: 'sssss', dateOfEstablishment: '0001-01-01T00:00:00', companyInformation: null, …}7: {$id: '29', id: 22, companyName: 'sssss', dateOfEstablishment: '0001-01-01T00:00:00', companyInformation: null, …}8: {$id: '31', id: 23, companyName: 'sssss', dateOfEstablishment: '0001-01-01T00:00:00', companyInformation: null, …}9: {$id: '33', id: 24, companyName: 'sssss', dateOfEstablishment: '0001-01-01T00:00:00', companyInformation: null, …}length: 10[[Prototype]]: Array(0)[[Prototype]]: Object

This I have in console from console.log, so yes is an array

Paul Ivan
  • 9
  • 1
  • 2
  • 3