Use directive in host of another Directive

后端 未结 1 1829
逝去的感伤
逝去的感伤 2020-12-15 23:51

I want to add a directive to an element from another directive by using the host property, but there doesn\'t seem to be a way to reference the other directive.



        
1条回答
  •  旧巷少年郎
    2020-12-16 00:03

    Directives are instantiated by Angular for selectors matching statically added HTML (element, id, attribute, class, ...) only.
    There is no way to instantiate directives using the host parameter of the @Component() or @Directive() decorator. There is also no way to create directives dynamically using ViewContainerRef.createComponent() (former DynamicComponentLoader)

    Getting a reference to another directive that was instantiated by Angular because of a statically added HTML on the same element is supported though.

    0 讨论(0)
提交回复
热议问题