How to access the Styles.scss file from within an Angular component

Asked

Viewed 226 times

0

I am working with Angular (project generated by @angular/cli), and the structure of my project is below:

src
 | - app
      | - foo
           | - foo.component.js
           | - foo.component.scss
           | - foo.component.html
 | - styles
      | - _variables.scss

In my file foo.component.scss I’m trying to access the file _variables.scss to pick up a variable that contains a standard color for the project. To do this, I am using the structure below:

@import '~/.../src/styles/_variables.scss';

foo {
    background-color: $color-red;
}

Is there any simpler way to import this file into component style sheets? or by creating a reference in the config files, or some other configuration?

1 answer

1


You have already defined the Angular project as Sass?

You can access your project folder, and type the following command.

ng set defaults.styleExt scss

Check your config is like this:

"defaults": {
  "styleExt": "scss",
  "component": {
  }
}
  • I ended up using a tag I found in the file schema angular-cli.json calling for stylePreprocessorOptions. with her I could tell the projects that the folder src/styles is a default folder for access to any component. so I just need to call the name of the file I want in there...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.