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
Post a Comment