4

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,155
  • 3
  • 19
  • 41

1 Answers1

9

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
  • 17,778
  • 11
  • 60
  • 104
  • 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