Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate files in <head> when reloading a template with angular-ui-router #191

Closed
inigo001 opened this issue Jun 1, 2015 · 4 comments
Closed
Labels

Comments

@inigo001
Copy link

inigo001 commented Jun 1, 2015

Hi and sorry if this question has been already asked. I have checked the #38 issue but I still don't see it very clear.

I have two HTML templates that I load using <a href=""> links. I use angular-ui-router to route, so the only thing that changes when clicking the link is the content of the ui-view. Each template has a .js and .css file associated with it that I load using ocLazyLoad.

Everything goes smoothly until I decide to go back and forth between the two pages. Everytime I click a link both .js and .css files get loaded again adding two duplicate lines of code to the <head>. The app still runs without problems since it loads the component just the first time, but the files keep getting loaded making the <head> a mess.

Here is the code I use to load the files with the routing.

angular
    .module('miApp')
    .config(config);

function config( $stateProvider , $locationProvider , $urlRouterProvider , $ocLazyLoadProvider  ) 
{

    $urlRouterProvider.otherwise("/");

    $stateProvider  
        .state('testState', {
            url: "/mirar",
            templateUrl: 'views/viewTest1.html',
            controller: 'view1Ctrl as miCtrl',
            resolve: { 
                loadMyCtrl: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load('scripts/controllers/view1Ctrl.js');
                }],
                loadMyCSS: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load('styles/testStyle.css');
                }],
            }
        })
        .state('testState2', {
            url: "/mirar2",
            templateUrl: 'views/viewTest2.html',
            controller: 'view2Ctrl as miCtrl',
            resolve: { 
                loadMyCtrl: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load('scripts/controllers/view2Ctrl.js');
                }],
                loadMyCSS: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load('styles/testStyle.css');
                }],
            }
        });

    $locationProvider.html5Mode(true);

    $ocLazyLoadProvider.config({
        debug: true
    });
}

Is there a solution or am I doing something wrong?

@ocombe
Copy link
Owner

ocombe commented Jun 1, 2015

Are you using ocLazyLoad 1.0.0 ? If so, could you check if you have the same problem with beta2? https://github.com/ocombe/ocLazyLoad/releases/tag/1.0.0-beta.2
I have my idea on where the problem might be.

@ocombe ocombe added the bug label Jun 1, 2015
@ocombe
Copy link
Owner

ocombe commented Jun 1, 2015

Ok I checked it on my own, and I know where the problem is, I'll fix this asap :)

@inigo001
Copy link
Author

inigo001 commented Jun 1, 2015

Yep, was on 1.0.0. Tested it on beta2 and worked fine.

Thanks a lot for your great work!

@ocombe
Copy link
Owner

ocombe commented Jun 1, 2015

Fixed in 1.0.1 !

@ocombe ocombe closed this as completed Jun 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants