Reputation: 593
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:
so as you can see there is the array in the _results. but how can i access it and loop it?
Upvotes: 16
Views: 9245
Reputation: 194
To access ith element in _results in the queryList, call toArray()
method:
this.queryListObj.toArray().[i]
Upvotes: 0
Reputation: 412
To access elements, you have to wait until its ready
this.hangchecks.changes.subscribe(a => a.forEach((b, i) => console.log(b)));
Upvotes: 4
Reputation: 657957
Call the toArray()
method:
this.hangchecks.toArray().forEach((item) => {
Upvotes: 26