interpolation to a css class in an external file angular 2

丶灬走出姿态 提交于 2019-12-24 07:49:52

问题


I'm wondering if is possible to pass a variable to a css class into an external css file in angular 2, like from:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app works!';
  bgc: string = 'orange'
}

then on the "app.component.css" I would like to pass like

.mydiv{ background: {{bgc}};  }

Is this possible?


回答1:


I don't think this would be possible.

If you need a style to change programmatically, I would suggest looking into ngStyle at the link below:

https://angular.io/docs/ts/latest/api/common/index/NgStyle-directive.html



来源:https://stackoverflow.com/questions/41903323/interpolation-to-a-css-class-in-an-external-file-angular-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!