Nadya S. Nadya S. - 8 months ago 207
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.


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