我很确定你可以通过这样做来实现它:
@Component({ /* ... */ })
export class FooComponent {
@ViewChildren(TooltipDirective, { read: ElementRef }) inputs: QueryList<ElementRef<HTMLInputElement>>;
ngAfterViewInit () {
this.inputs.forEach(input => {
console.log(input.nativeElement)
})
}
}
编辑:获取属性值
@ViewChildren(TooltipDirective) inputsDirs: QueryList<TooltipDirective>;
ngAfterViewInit () {
this.inputsDirs.forEach(inputDir => {
// The value of the attribute
console.log(inputDir.tooltip)
// The host element
console.log(inputDir.hostElem.nativeElement)
})
}
工具提示。指令。输电系统
constructor (public hostElem: ElementRef<HTMLInputElement>) { }