What is the convention when it comes to AngularJS directives and styling them?
Do I style via JS or stylesheet? How do I keep things self-contained and modular?
What is the convention when it comes to AngularJS directives and styling them?
Do I style via JS or stylesheet? How do I keep things self-contained and modular?
jsSn0wMan
On
There is no convention as this is an issue with other libraries like extjs. However, in extjs, each component has a config to put styles in much like inline styles.
My approach is to include a separate css with the directive as it nicely separates the styling. And since angular directives allow separate template, your html is nicely separated from the javascript as well.
Copyright © 2021 Jogjafile Inc.
It depends heavily on the framework you use. In many MVC frameworks, you can write your own view helpers which automatically append a JS-file and CSS-file belonging to the same directive. Otherwise, you can use directive templates or Shadow DOM.