angular 4 how to access ViewChildren _results

Viewed 7201

i have a list of checkboxes inside an ngFor:

    <md-checkbox
      #hangcheck
      [id]="hangout?.$key"
      class="mychecks"
      >
    I'm Interested
  </md-checkbox> 

i refrence them in the component like so:

@ViewChildren("hangcheck") hangchecks: QueryList<any>;

then in ngAfterViewInit i need to loop them:

  ngAfterViewInit(){
console.log('the array: ',this.hangchecks)
this.hangchecks._results.forEach((item) => {
  console.log('the item: ',item)
});
 }

but i get: Property '_results' is private and only accessible within class 'QueryList' in the console i see this: enter image description here so as you can see there is the array in the _results. but how can i access it and loop it?

2 Answers

To access elements, you have to wait until its ready

this.hangchecks.changes.subscribe(a => a.forEach((b, i) => console.log(b)));
Related