|
5 | 5 | * https://github.com/Yappli/angular-css-injector/ |
6 | 6 | */ |
7 | 7 | angular.module('angular.css.injector', []) |
8 | | -.service('cssInjector', [ |
9 | | - '$compile', |
10 | | - '$rootScope', |
11 | | - function($compile, $rootScope) |
12 | | - { |
| 8 | +.provider('cssInjector', function() { |
| 9 | + var singlePageMode = false; |
| 10 | + |
| 11 | + function CssInjector($compile, $rootScope){ |
13 | 12 | // Variables |
14 | 13 | var singlePageMode = false, |
15 | 14 | 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', []) |
59 | 58 | if(scope.injectedStylesheets !== undefined) |
60 | 59 | scope.injectedStylesheets = []; // Make it empty |
61 | 60 | }; |
62 | | - |
63 | | - // 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`) |
64 | | - var setSinglePageMode = function(bool) |
65 | | - { |
66 | | - if(bool !== true && bool !== false) |
67 | | - throw("Angular service `cssInjector` : function `setSinglePageMode` : Error parameter, boolean required."); |
68 | | - |
69 | | - singlePageMode = bool; |
70 | | - }; |
71 | | - |
| 61 | + |
72 | 62 | return { |
73 | 63 | add: addStylesheet, |
74 | | - removeAll: removeAll, |
75 | | - setSinglePageMode: setSinglePageMode, |
| 64 | + removeAll: removeAll |
76 | 65 | }; |
77 | | - } |
78 | | -]); |
| 66 | + } |
| 67 | + |
| 68 | + this.$get = function($compile, $rootScope){ |
| 69 | + return new CssInjector($compile, $rootScope); |
| 70 | + }; |
| 71 | + |
| 72 | + this.setSinglePageMode = function(mode){ |
| 73 | + singlePageMode = mode; |
| 74 | + return this; |
| 75 | + } |
| 76 | +}); |
0 commit comments