简体   繁体   中英

Using QueryList gives the first HTML element

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.

在此处输入图片说明

What am I doing wrong?

更改ViewChildViewChildren

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM