Hi, This repo is out of date. Check out the issues to know about the limitations. There is plenty of forks and you can probably find one more appropriate. Sorry guys, I have to choose my priorities. This code comes with a MIT license, feel free to improve and maintained it.
The code was tested with angular 1.4.x
A angularJS service to load dynamically CSS files. The original name of this project was angularDynamicStylesheets.
angular-css-injector is a AngularJS service allows you to load dynamically CSS files in your HTML page.
-
Your angular's app must be defined on the HTML tag of your page
<html ng-app="myApp"
-
Add the module "angular.css.injector" to your AngularJS apps
angular.module('myApp', ['angular.css.injector']);
-
Get this service where you want and add your css files in your HTML page ! Example here in a controller :
function MyCtrl($scope, cssInjector) { cssInjector.add("/path/to/your/css/file.css"); }
-
To remove all added CSS files when the page change (in a single page application), configure the
cssInjectorProvider
:myApp.config(function(cssInjectorProvider){ cssInjectorProvider.setSinglePageMode(true); });
-
To remove manually all added CSS files, call the function removeAll :
function MyCtrl($scope, cssInjector) { cssInjector.removeAll(); }
- IE >=
8
- FF >=
3.5
- Chrome >=
4
- Opera >=
10
No one (only angular of course).
Code tested with angular 1.2.14
The module and the service name changed name from v1.0
Be careful and update your code if you use a previous version < 1.0