0

I am having custom component like below. and i want to get id of component that we used in html file.

@Directive({
    selector: `[myattr]`
})
export class myclass
{
   // want to get reference where myattr defined 
    //#myid
}

in html i will define like below

<input #myid myattr />
Kbvin
  • 216
  • 3
  • 13

1 Answers1

0
@Directive({
    selector: `[myattr]`
})
export class myclass
{
   constructor(private elRef:ElementRef) {}

   ngAfterViewInit() {
     console.log(this.elRef.nativeElement);
   }
}
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567