Is it possible to access the child elements (specifically <img>
) of @ViewChild()
in Angular 2+ without explicitly declaring them?
Within template.html
<div #parent>
<!-- Other elements besides <img> can also be present -->
<img src="http://localhost/123.jpg" alt="">
</div>
Inside component.ts file
@ViewChild('parent') parent;
public getFirstChild() {
this.firstChild = this.parent.? //
}
The goal is to create a versatile component that makes use of:
<div #parent>
<ng-content></ng-content>
</div>
Therefore, it should be possible to retrieve and manipulate the child elements within #parent
without having to declare them explicitly.