我想创建一个角度为2的按钮组件。 在主机上,我必须设置一个动态生成的css类名。 (取决于绑定属性)nativeElement.classList.add()替代
主机上的[ngClass]不起作用。
我读过使用elementRef.nativeElement.classList.add(值)是不是最好的方式要么,因为班级名册不支持webworkers(左右)
什么是生成我最好的选择该类动态在主机上?
@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){}
}
'this.elementRef.nativeElement.className + ='md-'+ this.color_'? – dfsq