1

I need to add a attribute to the content via this directive.


@Directive({
  selector: '[myStructuralDirective]'
})
export class MyStructuralDirectiveDirective {
  @Input()
  set myStructuralDirective(key: string) {

    key ? (this.viewContainerRef.createEmbeddedView(this.templateRef), this.renderer.setAttribute(...)  ): this.viewContainerRef.clear();
  }

  constructor(
    private readonly renderer: Renderer2,
    private readonly templateRef: TemplateRef<any>,
    private readonly viewContainerRef: ViewContainerRef
  ) {}
}

usage:

 <custom-element-1 *myStructuralDirective="classProperty">Test custom element 1</custom-element-1>

I don't find any method exposed via templateRef to do so.

user3421622
  • 89
  • 1
  • 10
  • It looks like this is not currently supported but there are (hacky) workarounds: https://stackoverflow.com/questions/49867172/access-host-component-in-a-structural-directive – MikeJ Jan 17 '20 at 16:26

0 Answers0