Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 使用QueryList给出第一个HTML元素_Angular_Typescript_Angular10_Viewchild_Viewchildren - Fatal编程技术网

Angular 使用QueryList给出第一个HTML元素

Angular 使用QueryList给出第一个HTML元素,angular,typescript,angular10,viewchild,viewchildren,Angular,Typescript,Angular10,Viewchild,Viewchildren,我正在使用Angular 10,并尝试使用QueryList,代码如下(就像web上的许多示例一样) HTML 一些内容 TS @ViewChild('someID')someID:QueryList; 当在组件中运行console.log(this.someIds)时,在组件初始化之后,我实际上得到的是一个ElementRef对象(可能是第一个或最后一个div),而不是整个列表 我做错了什么?将查看儿童更改为查看儿童 @ViewChildren('someID') someIds: Qu

我正在使用Angular 10,并尝试使用QueryList,代码如下(就像web上的许多示例一样)

HTML

一些内容
TS

@ViewChild('someID')someID:QueryList;
当在组件中运行console.log(this.someIds)时,在组件初始化之后,我实际上得到的是一个ElementRef对象(可能是第一个或最后一个div),而不是整个列表


我做错了什么?

查看儿童更改为查看儿童

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

将“@ViewChild('someID')”更改为“@ViewChildren('someID')”@Andrei谢谢!!
  @ViewChild('someID') someIds: QueryList<ElementRef>;
@ViewChildren('someID') someIds: QueryList<ElementRef>;