interpolation to a css class in an external file a

2019-08-01 12:41发布

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条回答
Melony?
2楼-- · 2019-08-01 13:16

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

查看更多
登录 后发表回答