1

Let's say I have the following directive :


@Directive({
  selector: 'button[my-button], button[my-button-outline]',
})
export class ButtonComponent {
  @Input() color = 'primary';

  @HostBinding('class')
  public get colorClass(): string {
    return `btn btn-${this.color}`;
  }
}

I would like to assign a different class depending on if I used my-button or my-button-outline

Is this behavior possible in Angular 12 ?

There is a similar question, but without solution : Multiple directive selectors - find which selector was used in template

Crocsx
  • 2,534
  • 1
  • 28
  • 50
  • Something like this? https://stackblitz.com/edit/angular-ivy-689xbh?file=src/app/testi.directive.ts – enno.void Oct 21 '21 at 08:13
  • yeah, that looks like it works. I hoped a solution more "sugary" but that's looks like it s enough for me, thanks – Crocsx Oct 21 '21 at 08:50

0 Answers0