I have the below directive:
@Directive({
selector: '[changeColor]',
exportAs:'changeColor'
})
export class ColorDirective {
constructor(elem: ElementRef, renderer: Renderer2) {
renderer.setStyle(elem.nativeElement, 'color', 'red');
}
}
I have the below template:
<h1 changeColor>Hello</h1>
This works as expected and displays "Hello" in red. But, when I try to access a reference of the directive I get an error. For example, the below code:
<h1 #x=changeColor>Hello</h1>
{{x}}
produces the below error "There is no directive with "exportAs" set to "changeColor""
. Where am I going wrong?