I'm trying to get the ID's from the selected items in my PrimeNG DataTable. I'm getting this error but I can't find too much about in on Google...
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.)
This is my 'interface':
export interface Departement {
DepName;
ID;
}
This is 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 my component code how I want it to work, but it doesn't... (of course)
NGSelectedDepartementen: Departement;
for (let x of this.NGSelectedDepartementen) {
console.log(x.ID);
}
This is what's in my NGSelectedDepartementen when I select two 'departementen':
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]
Can anyone give me some example code for how I should do this?
Answer
Your NGSelectedDepartementen should be of type Departement[] instead of Departement. Except if the Departement instance is a class instance that implements the Iterable interface.
NGSelectedDepartementen: Departement[];
Answer by n00dl3
console.log(this.NGSelectedDepartementen)NGSelectedDepartementen, it would be hard to get to a solution.NGSelectedDepartementen