【发布时间】:2020-10-07 16:08:14
【问题描述】:
我有这个组件,我需要在宿主组件中动态添加动态类
@Component({
selector: 'test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class TestComponent implements OnInit {
@HostBinding('className') componentClass: string;
@Input() name: string;
constructor() {}
ngOnInit(): void {
this.componentClass = this.name ? `test-icons test-icons-${this.name}` : '';
}
}
这可行,但如果我尝试在我的组件上添加一个类,则会被控制期间添加的类覆盖。
例如,如果我愿意:
<test-component class="custom-class-i-added" [name]="'icon']></test-component>
class "custom-class-i-added" 消失了……我想创建一个系统,在现有的类中添加动态类……有没有办法?
【问题讨论】:
标签: angular typescript