Interpolation to css class in angular 2 external file

I am wondering if it is possible to pass a variable to a css class to an external css file in angular 2, for example:

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 "app.component.css" I would like to go through as

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

Is it possible?

+1
source share
1 answer

I do not think that would be possible.

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

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

0
source

Source: https://habr.com/ru/post/1012668/


All Articles