I'm having trouble extracting the IDs from the selected items in my PrimeNG DataTable. Despite searching on Google, I couldn't find much information about the error I'm encountering...
ERROR in C:/Users/*****/Documents/Octopus/Octopus 2.0/src/app/gebruikers/gebruikers.component.ts (200,33): Type must have a '[Symbol.iterator]()' method that returns an iterator.)
Below is the 'interface' I am using:
export interface Departement {
DepName;
ID;
}
This is the snippet of my html code:
<p-dataTable [value]="departementen" [rows]="3" class="thumbnail" resizableColumns="true" [paginator]="true" [pageLinks]="0"
[rowsPerPageOptions]="[3,5,10]" [globalFilter]="gbDepartementen" emptyMessage=""
[(selection)]="NGSelectedDepartementen">
<p-column [style]="{'width':'30px'}" selectionMode="multiple"></p-column>
<p-column [style]="{'width':'40px'}" field="ID" header="ID"></p-column>
<p-column field="DepName" header="Departement"></p-column>
</p-dataTable>
This is the part of my component code where I encounter issues:
NGSelectedDepartementen: Departement;
for (let x of this.NGSelectedDepartementen) {
console.log(x.ID);
}
When I select two 'departementen', this is the content of NGSelectedDepartementen:
Array[2]
0:Object
DepName:"Koninklijke Academie voor Schone Kunsten Antwerpen"
ID:16
__proto__:Object
1:Object
DepName:"Koninklijk Conservatorium Antwerpen"
ID:17
__proto__:Object
length:2
__proto__:Array[0]
Could someone provide me with example code on how to correctly implement this?
Answer
Your NGSelectedDepartementen variable should be of type Departement[]
instead of Departement
. Unless the Departement instance is a class implementing the Iterable interface.
NGSelectedDepartementen: Departement[];
Answer by n00dl3