1

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

4
  • I am more interested in knowing what you get on console.log(this.NGSelectedDepartementen) Commented Mar 22, 2017 at 16:02
  • Yeah at the moment nothing because the app won't run. "webpack: Failed to compile" Commented Mar 22, 2017 at 16:04
  • can you share the log and other details becoz unless you tell what is exactly there in NGSelectedDepartementen, it would be hard to get to a solution. Commented Mar 22, 2017 at 16:06
  • I added what's inside NGSelectedDepartementen Commented Mar 22, 2017 at 16:17

1 Answer 1

1

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[];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.