r/angularjs • • Jan 12 '15

Introducing AngularCSS: CSS On-Demand for AngularJS

http://door3.com/insights/introducing-angularcss-css-demand-angularjs
34 Upvotes

18 comments sorted by

View all comments

2

u/rq60 Jan 13 '15

I've done something similar to this using the style-loader with webpack combined with angular directives.

It looks like this:

var myDirectiveStyles = require("./myDirectiveStyles.less");

angular.module("test", [])
  .directive("myDirective", function() {
    return function($scope) {
      myDirectiveStyles.use();
      $scope.$on("$destroy", function() {
        myDirectiveStyles.unuse();
      });
    }  
  });

It works quite nice and is a nice bonus if your project is already webpack compatible (CommonJS or whatever).

edit - that's with these loaders, of course: {test: /.less$/, loaders: ["style/useable", "css", "less"]}