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

Remove dynamic stylesheets added #3

Open
xzegga opened this issue Sep 25, 2013 · 4 comments
Open

Remove dynamic stylesheets added #3

xzegga opened this issue Sep 25, 2013 · 4 comments

Comments

@xzegga
Copy link

xzegga commented Sep 25, 2013

how I can remove all dynamic stylesheets added before add new stylesheet in header on a single page application?

@GabrielDelepine
Copy link
Owner

Thanks for open this issue.

I updated the code to allow this feature.

Check the readme file.

@drelei
Copy link

drelei commented Apr 11, 2014

Thanks for adding this feature. I am noticing the behavior of "add" happening before the "removeAll" happening. Let me know if I'm setting this up properly

// app.js using ui-router
app.config(function($stateProvider, $urlRouterProvider, cssInjectorProvider) {
    cssInjectorProvider.setSinglePageMode(true);
    ...
    .state('users', {
            url: "/users",
            parent: 'authenticated',
            templateUrl: "/views/users/list.html",
            controller: 'UsersListCtrl',
            title: 'Users'
        })

// usersController.js
usersControllers.controller('UsersListCtrl', function ($scope, $http, cssInjector) {
    cssInjector.add("/css/pages/users/userList.css");

When I load the user list page, the proper style(body {color: red;}) gets applied from userList.css. Then I navigate to some other page like settings and the styling is removed as I see the removeAll call.

However, when I navigate to the user list page again, I see "add" being called in the console before the removeAll, essentially erasing the userList.css inclusion.

Please let me know if you have any insights.

@GabrielDelepine
Copy link
Owner

Hi @drelei : The function removeAll is fired on the event $locationChangeStart.

In my personal project, I'm doing a lazy loading for css and js files, so $locationChangeStart is always called before my controller be load.

Your example is an interesting case. Unfortunately I only have a dirty solution to recommend you today :

$timeout(function(){ cssInjector.add("/css/pages/users/userList.css"); }, 50); // 50ms is probably enough in all the case.

I'm looking for a clean fix, but I don't have enough time this days.

I reopen this issue until a clean fix be found.

@drelei
Copy link

drelei commented Apr 17, 2014

Hi @yappli ,

Thank you for your suggestion and the continued support of the project when available. I'm not sure if it's the way ui-router works, but I'm seeing the controller fired (add activity) before the $locationChangeStart which wipes everything out with the removeAll. I tried a workaround by performing the add via $locationChangeSuccess. However, it has a residual issue where going to the next page will end up performing the add from Page 1.

Hope that helps,

  • Dre

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants