1

Let's say I have the following Angular component:

// src/app/app.component.html
<stars [customColor]="blue">

And I have the following scss variable:

// src/_styles.scss
$color: blue;

How can I use the scss variable instead of duplicating blue?

To clarify, I want to access $color in app.component.html or app.component.ts.

Apparently it's possible to configure Webpack in a React app but I'm not sure if this is possible in Angular.

1 Answer 1

2

In your app.component.scss (or star.component.scss) file just import your styles:

@import './../_style.scss'

Then you can use your scss var

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the answer, but as far as I know, this only gives me access to $color in app.component.scss. How can I access it in app.component.html or app.component.ts?
This is not possible. (And I think there is not need). Make a smal my.vars.scss and import it to all your sub-components scss. There are some hacks to read the color code from an element, but it's not a usually way.
An other way is to use css variables (not scss): See: css-tricks.com/updating-a-css-variable-with-javascript
Thanks for adding to the discussion! I want to be able to change the color of stars without having to modify stars. See also Applying the open-closed principle to UI components

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.