I am developing an angular directive that converts dropdownlist to radioListbox. here is my initial code :
import { Directive, Input, TemplateRef, ViewContainerRef,OnInit } from '@angular/core';
@Directive({
selector: '[radioList]'
})
export class RadioListDirective implements OnInit {
constructor(private templateRef: TemplateRef<any>, private vcRef: ViewContainerRef) {
}
ngOnInit() {
console.log(this.templateRef);
this.vcRef.createEmbeddedView(this.templateRef);
}
}
and
<div>
test
</div>
<select *radioList><option>1</option><option>2</option></select>
It should log the TemplateRef
whose ElementRef
's nativeElement is a select
. But the result is and empty comment that its next element is the select
.
It should log the TemplateRef whose ElementRef 's nativeElement is a select
where did you read that? It works as intended – WhereverThe elementRef that is available on the templateRef as shown here just points to the DOM host element that Angular created for the template element - it's a comment node.
https://mcmap.net/q/1470098/-elementref-is-undefined-in-templateref – Wherever