diff --git a/README.md b/README.md
index c4f9721..3bb6b43 100644
--- a/README.md
+++ b/README.md
@@ -29,12 +29,11 @@ How to use ?
cssInjector.add("/path/to/your/css/file.css");
}
```
-4. To remove all added CSS files when the page change (in a single page application), set the single page mode :
+4. To remove all added CSS files when the page change (in a single page application), configure the `cssInjectorProvider`:
```javascript
- function MyCtrl($scope, cssInjector)
- {
- cssInjector.setSinglePageMode(true);
- }
+ myApp.config(function(cssInjectorProvider){
+ cssInjectorProvider.setSinglePageMode(true);
+ });
```
5. To remove manually all added CSS files, call the function removeAll :
diff --git a/angular-css-injector.js b/angular-css-injector.js
index 809ac4a..aac98b7 100644
--- a/angular-css-injector.js
+++ b/angular-css-injector.js
@@ -5,11 +5,10 @@
* https://github.com/Yappli/angular-css-injector/
*/
angular.module('angular.css.injector', [])
-.service('cssInjector', [
- '$compile',
- '$rootScope',
- function($compile, $rootScope)
- {
+.provider('cssInjector', function() {
+ var singlePageMode = false;
+
+ function CssInjector($compile, $rootScope){
// Variables
var singlePageMode = false,
head = angular.element(typeof jQuery == "undefined" ? document.querySelector('head') : 'head'), // TO make the code IE < 8 compatible, include jQuery in your page
@@ -59,20 +58,19 @@ angular.module('angular.css.injector', [])
if(scope.injectedStylesheets !== undefined)
scope.injectedStylesheets = []; // Make it empty
};
-
- // Used to set the boolean `singlePageMode`. If singlePageMode===TRUE, the function `removeAll` will be call every time the page change (based on the angular event `$locationChangeStart`)
- var setSinglePageMode = function(bool)
- {
- if(bool !== true && bool !== false)
- throw("Angular service `cssInjector` : function `setSinglePageMode` : Error parameter, boolean required.");
-
- singlePageMode = bool;
- };
-
+
return {
add: addStylesheet,
- removeAll: removeAll,
- setSinglePageMode: setSinglePageMode,
+ removeAll: removeAll
};
- }
-]);
+ }
+
+ this.$get = function($compile, $rootScope){
+ return new CssInjector($compile, $rootScope);
+ };
+
+ this.setSinglePageMode = function(mode){
+ singlePageMode = mode;
+ return this;
+ }
+});
diff --git a/angular-css-injector.min.js b/angular-css-injector.min.js
index cbe0ce3..3d7286a 100644
--- a/angular-css-injector.min.js
+++ b/angular-css-injector.min.js
@@ -1,2 +1 @@
-/* angular-css-injector - v1.0.1 - https://github.com/Yappli/angular-css-injector/ */
-angular.module("angular.css.injector",[]).service("cssInjector",["$compile","$rootScope",function(e,t){var n=false,r=angular.element(typeof jQuery=="undefined"?document.querySelector("head"):"head"),i;t.$on("$locationChangeStart",function(){if(n===true)u()});var s=function(){if(i===undefined)i=r.scope()};var o=function(t){s();if(i.injectedStylesheets===undefined){i.injectedStylesheets=[];r.append(e("")(i))}else{for(var n in i.injectedStylesheets){if(i.injectedStylesheets[n].href==t)return}}i.injectedStylesheets.push({href:t})};var u=function(){s();if(i.injectedStylesheets!==undefined)i.injectedStylesheets=[]};var a=function(e){if(e!==true&&e!==false)throw"Angular service `cssInjector` : function `setSinglePageMode` : Error parameter, boolean required.";n=e};return{add:o,removeAll:u,setSinglePageMode:a}}])
+angular.module("angular.css.injector",[]).provider("cssInjector",function(){function t(e,t){var n=false,r=angular.element(typeof jQuery=="undefined"?document.querySelector("head"):"head"),i;t.$on("$locationChangeStart",function(){if(n===true)u()});var s=function(){if(i===undefined)i=r.scope()};var o=function(t){s();if(i.injectedStylesheets===undefined){i.injectedStylesheets=[];r.append(e("")(i))}else{for(var n in i.injectedStylesheets){if(i.injectedStylesheets[n].href==t)return}}i.injectedStylesheets.push({href:t})};var u=function(){s();if(i.injectedStylesheets!==undefined)i.injectedStylesheets=[]};return{add:o,removeAll:u}}var e=false;this.$get=["$compile","$rootScope",function(e,n){return new t(e,n)}];this.setSinglePageMode=function(t){e=t;return this}})
\ No newline at end of file