Я разрабатываю директиву angular, которая преобразует раскрывающийся список в radioListbox. вот мой исходный код:
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);
}
}
а также
<div>
test
</div>
<select *radioList><option>1</option><option>2</option></select>
Он должен регистрировать TemplateRef
, чей nativeElement ElementRef
- это select
. Но результатом является пустой комментарий, что его следующим элементом является select
.
It should log the TemplateRef whose ElementRef 's nativeElement is a select
где вы это прочитали? Работает как задумано - person yurzui   schedule 08.05.2018The 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.
stackoverflow.com/a/44940608/5485167 - person yurzui   schedule 09.05.2018