]>
Commit | Line | Data |
---|---|---|
8afade26 C |
1 | import { Directive, ElementRef, Input, OnInit, Renderer2 } from '@angular/core' |
2 | import { PluginSelectorId } from '@shared/models' | |
3 | ||
4 | @Directive({ selector: '[myPluginSelector]' }) | |
5 | export class PluginSelectorDirective implements OnInit { | |
6 | @Input() pluginSelectorId: PluginSelectorId | |
7 | ||
8 | constructor ( | |
9 | private renderer: Renderer2, | |
10 | private hostElement: ElementRef<HTMLElement> | |
11 | ) { | |
12 | ||
13 | } | |
14 | ||
15 | ngOnInit () { | |
16 | const id = this.hostElement.nativeElement.getAttribute('id') | |
17 | if (id) throw new Error('Cannot set id on element that already has an id') | |
18 | ||
19 | this.renderer.setAttribute(this.hostElement.nativeElement, 'id', `plugin-selector-${this.pluginSelectorId}`) | |
20 | } | |
21 | } |