5

It's possible to share the same css file across the same angular 2 module?

I know that I can set View Encapsulation Emulated to inherited parent component css but I want to share the same style across one particular module of my app.

This is my app structure:

  • Main component
    • Module A (shared css style for this module)
      • Component 1
      • Component 2
    • Module B (shared css style for this module)
      • Component 1
      • Component 2
John
  • 1,697
  • 4
  • 27
  • 53

1 Answers1

10

Yes you can. Simply create a file, shared.scss for example. Now you can import it in you components style: @import './styles/shared.scss'; You could also add it to your styleUrls in your component.

Robin Dijkhof
  • 18,665
  • 11
  • 65
  • 116
  • 7
    I'm not sure but It seems this approach leads to css duplication for each of the components exporting it. https://stackoverflow.com/a/41491281/4572561 Does AOT compiler strip it? – Dzmitry Vasilevsky Oct 16 '18 at 14:48
  • Yes @DzmitryVasilevsky you are right, it would lead to duplication – Ninja420 Apr 01 '20 at 15:21