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 />
@Directive({
selector: `[myattr]`
})
export class myclass
{
constructor(private elRef:ElementRef) {}
ngAfterViewInit() {
console.log(this.elRef.nativeElement);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.