I need to dynamically bind an element reference from an object to my HTML in Angular. I have attempted the following:
<div #[sec_variable] ></div> OR <div #sec_variable ></div>
And then tried to retrieve it using @ViewChild(), but it always returns null.
<div class="nav-item" *ngFor="let input of inputs">
<div #[input.name] /></div>
</div>
Additionally,
@ViewChild('image',{static:true,read:ElementRef}) img?
ngOnInit(): void {
const label = this.renderer.createElement('label');
this.renderer.setAttribute(label, 'for', 'image');
this.renderer.appendChild(this.img.nativeElement, label)
}
However, these methods are not working for me. Is there a way to use it dynamically?