Structural directive - finding the element it is placed on

前端 未结 4 1813
闹比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:50

    All structural directives are added to elements. Angular never adds elements to the DOM. Therefore it's not possible to get the element a structural directive is added to.

    If you use the shorthand syntax with * like

    angular creates

    
      

    and because is not added, there is no way of getting it and because

    is not the element the structural directive is added to you also can't get this element using the directive reference.

提交回复
热议问题