In my Angular application, I want to upload css files in a modular way - each module has its own css file. That way I can easily add, remove or move modules.
The best way I've found so far is to create a service:
angular.module('cssLoadingService', []).factory("CssLoadingService", function () { return { loadCss: function (url) { if (document.createStyleSheet) { //IE document.createStyleSheet(url); } else { var link = document.createElement("link"); link.type = "text/css"; link.rel = "stylesheet"; link.href = url; document.getElementsByTagName("head")[0].appendChild(link); } } }; });
Each controller loads a css template. Although I introduce the path (by another service), it still seems to me that I am breaking the separation between logic and representation.
Is there any other elegant way (which does not include packing css files into one huge file)?
Roy tsabari
source share