One use of a directive could be to create reusable HTML elements that can be inserted into your page cleanly.
I've used this idea several times in my current project but I cannot decide where the correct place to include CSS declarations for a given directive are. So far I've thought of:
I realise I could add this into any site-wide global css as well, but again this isn't good practice as I should be able to lift a directive from one project to a completly disjoint other project.
Where is the correct place to put CSS declarations for a given directive that is intended to be a reusable HTML segment?
Thanks in advance!
Styles should always be stored in a separate file. Unless you are coding something that will be embedded in other people's pages or send HTML emails, inline style is a bad idea (and even for emails you can inline your style easily from an external file). Style link tag inside the template just obscures your application enforcing developers to read all your directives, who might not even be aware of AngularJS.
For me, you want an answer for the wrong question. Your style shouldn't care whether you are using AngularJS or not. When coding CSS, then you follow good CSS practices. Directives are just HTML views that can benefit from class binding, but should never be a factor for how to organize your CSS. Just pick a CSS structure (BEM, OOCSS, SMACSS, Atomic Design, etc) and make your team and yourself follow it.
tl;dr Styles shouldn't care what behavior layer are using. Use good CSS practices and in this case, a good CSS practice is to put your styles in a external stylesheet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With