Nadya S.
Nadya S.

Reputation: 43

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.

Upvotes: 3

Views: 4818

Answers (1)

Poul Kruijt
Poul Kruijt

Reputation: 71891

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 file should not be compiled. Which means you can only 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

Upvotes: 9

Related Questions