Nadya S. Nadya S. - 1 month ago 71
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

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