I am trying to create a button component in angular 2. On the host, I have to set the dynamically generated css class name. (depending on the bound property)
'[ngClass]' on the host does not work.
I read that using elementRef.nativeElement.classList.add (value) element is also not the best way, because the List class is not supported on web pages (or so)
What are my best features for dynamically creating a class on a host?
@Component({ selector: '[md-button]', }) export class MdButton { color_: string; @Input set color() { this.color_ = value; if (this.elementRef !== undefined) { this.elementRef.nativeElement.classList.add('md-' + this.color_); } } get color(): string { return this.color_; } constructor(public elementRef: ElementRef){} }
source share