Structural directive - finding the element it is placed on

前端 未结 4 1815
闹比i
闹比i 2021-02-07 05:25

With a structural directive, how would I get a hold of the (native) element the directive is on? With a normal directive, the ElementRef has it\'s nativeElement pointing to it -

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-07 05:30

    This isn't pretty, but worked for me:

    this.viewContainer.get(0).rootNodes[0]
    

    I used it when implementing a version of *ngIf directive but with animation: animatedIf.

提交回复
热议问题