Custom Structural Directive

Your own directive that adds or removes template blocks.

What is Custom Structural Directive?

A custom structural directive adds or removes parts of the template, like your own @if. It uses TemplateRef and ViewContainerRef.

@Directive({ selector: '[appIfAdmin]' })
export class IfAdmin {
  constructor() {
    if (inject(AuthService).isAdmin())
      inject(ViewContainerRef).createEmbeddedView(inject(TemplateRef));
  }
}

Level: Master · More Angular terms at this level

Updated