{"id":14973159,"url":"https://github.com/castillo-io/angular-css","last_synced_at":"2025-12-12T04:13:47.092Z","repository":{"id":25042943,"uuid":"28462713","full_name":"castillo-io/angular-css","owner":"castillo-io","description":"CSS on-demand for AngularJS [Looking for New Maintainers]","archived":false,"fork":false,"pushed_at":"2017-04-15T02:06:32.000Z","size":984,"stargazers_count":468,"open_issues_count":43,"forks_count":85,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-02T06:43:10.584Z","etag":null,"topics":["angularjs","css","javascript","ngroute","stylesheets","ui-router"],"latest_commit_sha":null,"homepage":"http://castillo-io.github.io/angular-css/#/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mini-you/avatar-creator","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/castillo-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-24T21:43:34.000Z","updated_at":"2025-02-28T11:06:53.000Z","dependencies_parsed_at":"2022-09-11T04:22:51.809Z","dependency_job_id":null,"html_url":"https://github.com/castillo-io/angular-css","commit_stats":null,"previous_names":["door3/angular-css"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/castillo-io%2Fangular-css","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/castillo-io%2Fangular-css/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/castillo-io%2Fangular-css/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/castillo-io%2Fangular-css/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/castillo-io","download_url":"https://codeload.github.com/castillo-io/angular-css/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999859,"owners_count":21031046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angularjs","css","javascript","ngroute","stylesheets","ui-router"],"created_at":"2024-09-24T13:48:14.535Z","updated_at":"2025-12-12T04:13:42.058Z","avatar_url":"https://github.com/castillo-io.png","language":"JavaScript","readme":"# AngularCSS\n\n##### CSS on-demand for AngularJS\nOptimize the presentation layer of your single-page apps by dynamically injecting stylesheets as needed.\n\nAngularCSS listens for [route](https://github.com/angular/bower-angular-route) (or [states](https://github.com/angular-ui/ui-router)) change events, adds the CSS defined on the current route and removes the CSS from the previous route. It also works with directives in the same fashion with the compile and scope destroy events. See the code samples below for more details.\n\n##### Read the Article\n\n[Introducing AngularCSS: CSS On-Demand for AngularJS](http://www.castillo.io/blog/2015/2/1/introducing-angularcss-css-on-demand-for-angularjs)\n\n### Demos\n\n[Angular's ngRoute Demo](http://castillo-io.github.io/angular-css) ([source](../gh-pages/app.routes.js))\n\n[UI Router Demo](http://castillo-io.github.io/angular-css/states.html) ([source](../gh-pages/app.states.js))\n\n\n### Quick Start\n\nInstall and manage with [Bower](http://bower.io) or [jspm](http://jspm.io). A [CDN](http://cdnjs.com/libraries/angular-css) is also provided by cdnjs.com\n\n``` bash\n$ bower install angular-css\n```\n\n``` bash\n$ jspm install github:castillo-io/angular-css\n```\n\n\n1) Include the required JavaScript libraries in your `index.html` (ngRoute and UI Router are optional). \n\n``` html\n\u003cscript src=\"/libs/angularjs/1.5.6/angular.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"/libs/angularjs/1.5.6/angular-routes.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"/libs/angular-css/angular-css.min.js\"\u003e\u003c/script\u003e\n```\n\n2) Add `angularCSS` as a dependency for your app.\n\n``` js\nvar myApp = angular.module('myApp', ['ngRoute','angularCSS']);\n```\n\nNOTE: The module name \"door3.css\" is now deprecated.\n\n### Examples\n\nThis module can be used by adding a css property in your routes values, directives or by calling the `$css` service methods from controllers and services.\n\nThe css property supports a string, an array of strings, object notation or an array of objects.\n\nSee examples below for more information.\n\n#### In Components\n\n``` js\nmyApp.component('myComponent', {\n  css: 'my-component/my-component.css' // \u003c--- magic!\n  templateUrl: 'my-component/my-component.html',\n});\n```\n\n#### In Directives\n\n``` js\nmyApp.directive('myDirective', function () {\n  return {\n    restrict: 'E',\n    templateUrl: 'my-directive/my-directive.html',\n    /* Binding css to directives */\n    css: 'my-directive/my-directive.css'\n  }\n});\n```\n\n\n#### In Controllers\n\n``` js\nmyApp.controller('pageCtrl', function ($scope, $css) {\n\n  // Binds stylesheet(s) to scope create/destroy events (recommended over add/remove)\n  $css.bind({ \n    href: 'my-page/my-page.css'\n  }, $scope);\n\n  // Simply add stylesheet(s)\n  $css.add('my-page/my-page.css');\n\n  // Simply remove stylesheet(s)\n  $css.remove(['my-page/my-page.css','my-page/my-page2.css']);\n\n  // Remove all stylesheets\n  $css.removeAll();\n\n});\n```\n\n\n#### For Routes (Angular's ngRoute)\n\nRequires [ngRoute](https://github.com/angular/bower-angular-route) as a dependency\n\n\n``` js\nmyApp.config(function($routeProvider) {\n\n  $routeProvider\n    .when('/page1', {\n      templateUrl: 'page1/page1.html',\n      controller: 'page1Ctrl',\n      /* Now you can bind css to routes */\n      css: 'page1/page1.css'\n    })\n    .when('/page2', {\n      templateUrl: 'page2/page2.html',\n      controller: 'page2Ctrl',\n      /* You can also enable features like bust cache, persist and preload */\n      css: {\n        href: 'page2/page2.css',\n        bustCache: true\n      }\n    })\n    .when('/page3', {\n      templateUrl: 'page3/page3.html',\n      controller: 'page3Ctrl',\n      /* This is how you can include multiple stylesheets */\n      css: ['page3/page3.css','page3/page3-2.css']\n    })\n    .when('/page4', {\n      templateUrl: 'page4/page4.html',\n      controller: 'page4Ctrl',\n      css: [\n        {\n          href: 'page4/page4.css',\n          persist: true\n        }, {\n          href: 'page4/page4.mobile.css',\n          /* Media Query support via window.matchMedia API\n           * This will only add the stylesheet if the breakpoint matches */\n          media: 'screen and (max-width : 768px)'\n        }, {\n          href: 'page4/page4.print.css',\n          media: 'print'\n        }\n      ]\n    });\n\n});\n```\n\n#### For States (UI Router)\n\nRequires [ui.router](https://github.com/angular-ui/ui-router) as a dependency\n\n\n``` js\nmyApp.config(function($stateProvider) {\n\n  $stateProvider\n    .state('page1', {\n      url: '/page1',\n      templateUrl: 'page1/page1.html',\n      css: 'page1/page1.css'\n    })\n    .state('page2', {\n      url: '/page2',\n      templateUrl: 'page2/page2.html',\n      css: {\n        href: 'page2/page2.css',\n        preload: true,\n        persist: true\n      }\n    })\n    .state('page3', {\n      url: '/page3',\n      templateUrl: 'page3/page3.html',\n      css: ['page3/page3.css','page3/page3-2.css'],\n      views: {\n        'state1': {\n          templateUrl: 'page3/states/page3-state1.html',\n          css: 'page3/states/page3-state1.css'\n        },\n        'state2': {\n          templateUrl: 'page3/states/page3-state2.html',\n          css: ['page3/states/page3-state2.css']\n        },\n        'state3': {\n          templateUrl: 'page3/states/page3-state3.html',\n          css: {\n            href: 'page3/states/page3-state3.css'\n          }\n        }\n      }\n    })\n    .state('page4', {\n      url: '/page4',\n      templateUrl: 'page4/page4.html',\n      views: {\n        'state1': {\n          templateUrl: 'states/page4/page4-state1.html',\n          css: 'states/page4/page4-state1.css'\n        },\n        'state2': {\n          templateUrl: 'states/page4/page4-state2.html',\n          css: ['states/page4/page4-state2.css']\n        },\n        'state3': {\n          templateUrl: 'states/page4/page4-state3.html',\n          css: {\n            href: 'states/page4/page4-state3.css'\n          }\n        }\n      },\n      css: [\n        {\n          href: 'page4/page4.css',\n        }, {\n          href: 'page4/page4.mobile.css',\n          media: 'screen and (max-width : 768px)'\n        }, {\n          href: 'page4/page4.print.css',\n          media: 'print'\n        }\n      ]\n    });\n\n});\n```\n\n### Responsive Design\n\nAngularCSS supports \"smart media queries\". This means that stylesheets with media queries will be only added when the breakpoint matches.\nThis will significantly optimize the load time of your apps.\n\n```js\n$routeProvider\n  .when('/my-page', {\n    templateUrl: 'my-page/my-page.html',\n    css: [\n      {\n        href: 'my-page/my-page.mobile.css',\n        media: '(max-width: 480px)'\n      }, {\n        href: 'my-page/my-page.tablet.css',\n        media: '(min-width: 768px) and (max-width: 1024px)'\n      }, {\n        href: 'my-page/my-page.desktop.css',\n        media: '(min-width: 1224px)'\n      }\n    ]\n  });\n```\n\nEven though you can use the `media` property to specify media queries, the best way to manage your breakpoints is by settings them in the provider's default settings. For example:\n\n```js\nmyApp.config(function($routeProvider, $cssProvider) {\n\n  angular.extend($cssProvider.defaults, {\n    breakpoints: {\n      mobile: '(max-width: 480px)',\n      tablet: '(min-width: 768px) and (max-width: 1024px)',\n      desktop: '(min-width: 1224px)'\n    }\n  });\n\n  $routeProvider\n    .when('/my-page', {\n      templateUrl: 'my-page/my-page.html',\n      css: [\n        {\n          href: 'my-page/my-page.mobile.css',\n          breakpoint: 'mobile'\n        }, {\n          href: 'my-page/my-page.tablet.css',\n          breakpoint: 'tablet'\n        }, {\n          href: 'my-page/my-page.desktop.css',\n          breakpoint: 'desktop'\n        }\n      ]\n    });\n\n});\n```\n\n\n### Config\n\nYou can configure AngularCSS at the global or stylesheet level.\n\n#### Configuring global options\n\nThese options are applied during your app's `config` phase or via `$cssProvider`.\n\n``` js\nmyApp.config(function($cssProvider) {\n\n  angular.extend($cssProvider.defaults, {\n    container: 'head',\n    method: 'append',\n    persist: false,\n    preload: false,\n    bustCache: false\n  });\n\n});\n```\n\n#### Configuring CSS options\n\nThese options are applied at the stylesheet level.\n\n``` js\ncss: {\n  href: 'file-path.css',\n  rel: 'stylesheet',\n  type: 'text/css',\n  media: false,\n  persist: false,\n  preload: false,\n  bustCache: false,\n  weight: 0\n}\n```\n\n### Support\n\nAngularCSS is fully supported by AngularJS \u003e= v1.3 \u0026\u0026 \u003c= v1.5\n\nThere is partial support for AngularJS 1.2. It does not support `css` property via DDO (Directive Definition Object).\nThe workaround is to bind (or add) the CSS in the directive's controller or link function via `$css` service.\n\n``` js\nmyApp.directive('myDirective', function () {\n  return {\n    restrict: 'E',\n    templateUrl: 'my-directive/my-directive.html',\n    controller: function ($scope, $css) {\n      $css.bind('my-directive/my-directive.css', $scope);\n    }\n  }\n});\n```\n\n### Angular 2\n\nCan I use AngularCSS in Angular 2?\n\nAngularCSS is not necessary in Angular 2! Angular 2 ships with a similar feature out of the box. It's called `styles` and `styleUrls` and it looks like this:\n\n``` js\n@Component({\n  selector: 'my-component',\n  templateUrl: 'app/components/my-component/my-component.html',\n  styleUrls: ['app/components/my-component/my-component.css'],\n})\n```\n\n#### Browsers\n\nChrome, Firefox, Safari, iOS Safari, Android and IE9+\n\nIE9 Does not support [matchMedia](http://caniuse.com/#feat=matchmedia) API. This means that in IE9, stylesheets with media queries will be added without checking if the breakpoint matches.\n\n\n### Contributing\n\nPlease submit all pull requests the against master branch. If your pull request contains JavaScript patches or features, you should include relevant unit tests.\n\n### Copyright and license\n\n```\nThe MIT License\n\nCopyright (c) 2017 Alex Castillo\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcastillo-io%2Fangular-css","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcastillo-io%2Fangular-css","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcastillo-io%2Fangular-css/lists"}