在外部文件中插入 CSS 类 角度 2.



我想知道是否可以将一个变量传递给 css 类到角度 2 中的外部 css 文件中,例如:

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'
}

然后在"app.component.css"上,我想像

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

这可能吗?

我认为这是不可能的。

如果您需要以编程方式更改样式,我建议您在下面的链接中查看ngStyle:

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

最新更新