Angular2 dynamic change CSS property

前端 未结 5 1373
粉色の甜心
粉色の甜心 2020-12-01 02:07

We are making an Angular2 application and we want to be able to somehow create a global CSS variable (and update the properties\' values whenever changed wh

5条回答
  •  青春惊慌失措
    2020-12-01 02:19

    I did this plunker to explore one way to do what you want.

    Here I get mystyle from the parent component but you can get it from a service.

    import {Component, View} from 'angular2/angular2'
    
    @Component({
      selector: '[my-person]',
      inputs: [
        'name',
        'mystyle: customstyle'
      ],
      host: {
        '[style.backgroundColor]': 'mystyle.backgroundColor'
      }
    })
    @View({
      template: `My Person Component: {{ name }}`
    })
    export class Person {}
    

提交回复
热议问题