in Angular component, I am trying to create a new input html element and insert in specific location of the template
the component code
@ViewChild('pickerLocation', { static: false }) pLocationSpan: ElementRef<HTMLSpanElement>;
constructor(
private elementRef: ElementRef,
private renderer: Renderer2,
@Inject(DOCUMENT) private document: Document) { }
ngOnInit(): void {
const pickerInput = this.renderer.createElement('INPUT');
const picker = new TempusDominus(pickerInput);
this.renderer.appendChild(this.pLocationSpan.nativeElement, pickerInput);
}
the template code
<div class="col-sm-6">
<label for="datetimepickerInput">{{label}}</label>
<span id="locationSpan" ngModel #pickerLocation></span>
<span class="input-group-text">
<span class="fa-solid fa-calendar"></span>
</span>
</div>
however if I changed the line
this.renderer.appendChild(this.pLocationSpan.nativeElement, pickerInput);
to
this.renderer.appendChild(this.elementRef.nativeElement, pickerInput);
it works, however I need the input in specific location. so what could be the problem??