[英]Get custom component reference in angular?
我有如下的自定義組件。 我想獲取我們在html文件中使用的組件的ID。
@Directive({
selector: `[myattr]`
})
export class myclass
{
// want to get reference where myattr defined
//#myid
}
在HTML中,我將定義如下
<input #myid myattr />
@Directive({
selector: `[myattr]`
})
export class myclass
{
constructor(private elRef:ElementRef) {}
ngAfterViewInit() {
console.log(this.elRef.nativeElement);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.