Ну, это не очень понятно, но если я правильно понял, вы можете использовать @ViewChildren
, что в основном несколько @ViewChild
.
Этот стек * блик показывает, как вы можете его использовать, и, как вы видите, его очень легко использовать.
import { Component, QueryList, ElementRef, ViewChildren } from '@angular/core';
@Component({
selector: 'my-app',
template: `<hello name="{{ name }}"></hello>
<div
*ngFor="let index of [1, 2, 3, 4, 5]"
(mouseover)="hovered(divs)"
#divs>
This is the div n° {{ index }}
</div>`,
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
@ViewChildren('divs') divs: QueryList<ElementRef<HTMLDivElement>>;
name = 'Angular';
hovered(div: HTMLDivElement) {
// Getting from the query list
const corresponding = this.divs.find(_div => _div.nativeElement === div).nativeElement;
// they are the same
console.log(corresponding);
console.log(corresponding === div);
console.log(div);
}
}