1

I'm using Angular 10, and trying to use QueryList, with the code below (just like many examples on the web)

HTML

<div *ngFor="let i of [1,2,3,4]" #someID>some content</div>

TS

  @ViewChild('someID') someIds: QueryList<ElementRef>;

When running console.log(this.someIds) in the component, after the component initialization, I'm actually getting an ElementRef object (probably the first or the last div) and not the whole list.

enter image description here

What am I doing wrong?

1
  • 4
    change ` @ViewChild('someID')` to ` @ViewChildren('someID')` Commented Oct 22, 2020 at 12:59

1 Answer 1

2

Change ViewChild to ViewChildren

@ViewChildren('someID') someIds: QueryList<ElementRef>;
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.