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

后端 未结 7 1959
眼角桃花
眼角桃花 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 16:13

    You can do the following:

    import {Component} from "@angular/core"
    
    @Component({
        selector: "[textbox]",
        host: {"class": "first-class secondClass ThirdClass AnYClaSs"},
        template: ...                                            
    })
    export class MyComponent { }
    

    Which is imo way more straightforward than introducing a variable.
    Should work in Angular2 rc5, rc6, rc7, final. May work in earlier versions, but didnt try it.

    0 讨论(0)
提交回复
热议问题