You may use a directive to set your dynamic attributes.
Look at https://stackblitz.com/edit/angular-hnjfrg?file=src%2Fapp%2Fdynamic-attr.directive.ts to get a glimpse at how to use it.
You may use the directive like this:
<p [dynamicAttr]="'color'" attrValue="red"></p>
and access the directive values like this:
constructor(el: ElementRef) {
this.element = el;
}
ngAfterViewInit() {
console.log('Dynamic attribute: ', this.dynamicAttr);
this.element.nativeElement.style[this.dynamicAttr] = this.attrValue;
}
You may use the hook according to your use case. I have just used ngAfterViewInit
to set things up only once the view renders.