Adding css file to dom html in Angularjs 2 -


i have variable in component file stores css file.

var x = '.someclass { background: pink; } .someclass1 { background: purple; }' 

how can paste in style tag dom.

i tried this.

this.globalstyles= this.sanitized.bypasssecuritytruststyle(x);  <style [style]='globalstyles'></style> 

first, please notice mixing 2 different concepts. styles , classes not same. in case have:

var x = '.someclass { background: pink; } .someclass1 { background: purple; }' 

here x containing definition 2 classes. according experience, should declare classes inside of .css or .scss or .less file, instance inside of your_component_name.scss file contain classes instead of x variable.

after, able use classes in html tags this:

<some-element [ngclass]="'someclass someclass1'"></some-element> 

for more info read docs. hope helps!!


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -