Use variable in style tag in angular template?

前端 未结 4 1686
野性不改
野性不改 2021-02-20 01:55

I am working on angular 5 application, and I have requirement of applying dynamic css in style tag in template. I have tried some solutions but they are not working.

app

4条回答
  •  遇见更好的自我
    2021-02-20 02:17

    You can use [ngStyle] directive:

    
     This is angular 5 application
    
    

    Or like so:

    
     This is angular 5 application
    
    

    And in component:

    applyStyles() {
        const styles = {'color' : 'red'};
        return styles;
    }
    

提交回复
热议问题