插入到外部文件 angular 2 中的 css 类 [英] interpolation to a css class in an external file angular 2

查看:16
本文介绍了插入到外部文件 angular 2 中的 css 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

<小时>

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


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

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

这可能吗?

推荐答案

我认为这不可能.

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

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

这篇关于插入到外部文件 angular 2 中的 css 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆