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

Commit 0b187cd

Browse files
Gabriel DelépineGabriel Delépine
Gabriel Delépine
authored and
Gabriel Delépine
committed
Merge pull request #6 from kleiinnn/master
Use provider to configure single page application mode.
2 parents 07e9813 + 3c76992 commit 0b187cd

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ How to use ?
2929
cssInjector.add("/path/to/your/css/file.css");
3030
}
3131
```
32-
4. To remove all added CSS files when the page change (in a single page application), set the single page mode :
32+
4. To remove all added CSS files when the page change (in a single page application), configure the `cssInjectorProvider`:
3333
```javascript
34-
function MyCtrl($scope, cssInjector)
35-
{
36-
cssInjector.setSinglePageMode(true);
37-
}
34+
myApp.config(function(cssInjectorProvider){
35+
cssInjectorProvider.setSinglePageMode(true);
36+
});
3837
```
3938

4039
5. To remove manually all added CSS files, call the function removeAll :

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+
});

angular-css-injector.min.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)