Hello, I am facing some challenges with Aurelia and I am a beginner so please bear with me if this is a simple issue.
I can't seem to access the 'style' property of the 'Element' object. Here's what I have been trying:
@customAttribute('test-attr')
@autoinject
export class TestAttr {
private element : Element ;
constructor( element : Element) {
this.element = element ;
}
attached() {
//now i want to get a access to 'style'
this.element.style.color = 'red'
//this gives a error - Element declaration doesnt contain 'style' property
}
}
It appears that the TypeScript declaration for 'Element' does not include the 'style' property, which makes sense. However, Aurelia has its own extended version of Element causing inconsistency.
I managed to find a workaround by manually injecting Element and declaring it as HTMLElement in the class. So here is the modified code:
@customAttribute('test-attr')
@inject(Element)
export class TestAttr {
private element : HTMLElement ;
constructor( element : HTMLElement) {
this.element = element ;
}
attached() {
this.element.style.color = 'red'
//above works fine
}
}
But ideally, I would like to use '@autoinject' because it's simpler and more elegant. Do you see anything wrong with my usage of autoinject? Or could this possibly be a bug?