Nadya S. Nadya S. - 1 year ago 343
Sass (Sass) Question

Sass variables in Angular2 components

I use Angular2 and angular-cli in my project. I defined some Sass variables in the global style.scss file. How can I access these variables from my custom components (from component.scss)? đťaybe I have to import the separate file with these variables in each component.scss file.

Answer Source

You should put your variables inside a seperate .scss file like _vars.scss. Notice the underscore in front of the name. This will tell the compiler that the output of the file should not be embedded if you use it with @import.

Then for instance in your component.scss you can do (at the top of your file):

@import "path/to/vars";

No need to add the underscore nor the extension

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download