Is it possible to add a dynamic class to host in Angular 2?

后端 未结 7 2023
眼角桃花
眼角桃花 2021-01-01 15:47

I know that in Angular2 I can add a class \'red\' to a component\'s selector element by doing this:

@Component({
    selector: \'selector-el\',
    host: {
          


        
7条回答
  •  情深已故
    2021-01-01 15:54

    If you like to change it from outside you can combine @HostBinding and @Input():

    @Component({
        selector: 'my-component',
        template: ``
    })
    export class MyComponent {
        @HostBinding('class.your-class') @Input() isSelected: boolean;
    }
    

提交回复
热议问题