Skip to content
This repository was archived by the owner on Feb 8, 2023. It is now read-only.

Commit c375964

Browse files
committed
use a provider to configure if the appliaction is a single page app
1 parent 07e9813 commit c375964

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

angular-css-injector.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
* https://github.com/Yappli/angular-css-injector/
66
*/
77
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){
1312
// Variables
1413
var singlePageMode = false,
1514
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', [])
5958
if(scope.injectedStylesheets !== undefined)
6059
scope.injectedStylesheets = []; // Make it empty
6160
};
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+
7262
return {
7363
add: addStylesheet,
74-
removeAll: removeAll,
75-
setSinglePageMode: setSinglePageMode,
64+
removeAll: removeAll
7665
};
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

Comments
 (0)