簡體   English   中英

獲取角度的自定義組件參考?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM