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

Error on lazy load from a lazy loaded file #43

Closed
citosid opened this issue Jul 22, 2014 · 14 comments
Closed

Error on lazy load from a lazy loaded file #43

citosid opened this issue Jul 22, 2014 · 14 comments
Labels

Comments

@citosid
Copy link

citosid commented Jul 22, 2014

I have one problem. Your module works very fine, however when I try to lazy load from a lazy loaded file it says:

Error: jsLoader is not a function
this.$get</filesLoader@https : //localhost/js/angular/includes/lazyload.js:245:1

I can add the same function you have in line 104, but while the error is not showed anymore it does not load the files either... Am I doing something wrong?

angular.module("StreamApp").config(function($stateProvider, $controllerProvider, $ocLazyLoadProvider) {
    $ocLazyLoadProvider.config({
        debug: true,
        events: true
    });
    $stateProvider.state("controller", {
        url: "/:controller/:action",
        controller: function($rootScope, $state, $stateParams, $ocLazyLoad) {
            if (!$rootScope.controllers)
                $rootScope.controllers = {};

            if (!$rootScope.controllers[$stateParams.controller]) {
                $ocLazyLoad.load([{
                    files: [
                        "/js/angular/controller/" + $stateParams.controller + ".js"
                    ]
                }]).then(function() {
                    $rootScope.controllers[$stateParams.controller] = true;
                    $state.go($stateParams.controller + ( $stateParams.action ? ("." + $stateParams.action) : "" ));
                });
            }
            log($stateParams);
        }
    })
});
@citosid
Copy link
Author

citosid commented Jul 23, 2014

Any ideas?

@ocombe
Copy link
Owner

ocombe commented Jul 23, 2014

Oups sorry I forgot to answer yesterday.
The error line points to jsLoader(jsFiles, function(err) {
But jsLoader has to be defined here, it shouldn't possible to be something else than a function ...
Could you edit the ocLazyLoad.js file and add a console.log(jsLoader) line 244 to see what's going on here ?

@citosid
Copy link
Author

citosid commented Jul 23, 2014

It is ok. Thanks for your answer.

This is the result:

captura de pantalla 2014-07-23 a la s 10 07 58 a m

@ocombe
Copy link
Owner

ocombe commented Jul 23, 2014

Ok, is it possible that you are lazy loading ocLazyLoad somewhere ?
Is it possible to have the code of your lazy loaded file so that I can try to reproduce the bug ?
Could you search for the function init at the end of the file: function init(element) { and put a console.log in it to check if it's called 2 times ?

@citosid
Copy link
Author

citosid commented Jul 23, 2014

The first file lazy loaded is the one paste above. As you can see on it, it tries to load other files, but there is when it fails. I'm trying to create a plnkr snippet, but I cannot make it work.

I'm not lazy loading ocLazyLoad anywhere else. Actually, that code is all I have there.

@ocombe
Copy link
Owner

ocombe commented Jul 23, 2014

Ok I can reproduce.

You're not supposed to do a

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

in the lazy loaded module. The lib has already been configured. Just remove this and you'll be fine
I'll add a safeguard to prevent this problem.

@citosid
Copy link
Author

citosid commented Jul 23, 2014

Thanks @ocombe! However, that does not fix the error either :(

captura de pantalla 2014-07-23 a la s 10 28 01 a m

And by the way, this is the pnkr I cannot make work.
http://plnkr.co/edit/bf7D3wSWb4fhCooBVRKC

@ocombe
Copy link
Owner

ocombe commented Jul 23, 2014

Ok, I finish the fix and I'll release it in 10mn.

@ocombe ocombe closed this as completed in c590579 Jul 23, 2014
@ocombe
Copy link
Owner

ocombe commented Jul 23, 2014

It's available in release 0.3.2 :)

@ocombe ocombe added the bug label Jul 23, 2014
@citosid
Copy link
Author

citosid commented Jul 23, 2014

Thanks a lot. It fixes that error. Now are being loaded. You know what, I think I know why it is "configured" again.

I have this in my main app file:

angular.module("StreamApp", [ "ngCookies", "ngRoute", "ui.router", "oc.lazyLoad", "ngAnimate" ]);

angular.module("StreamApp")
.config(function($ocLazyLoadProvider, $httpProvider) {
    $ocLazyLoadProvider.config({
        loadedModules: ["StreamApp"],
        debug: true,
        events: false
    });

And in the main controller:

$ocLazyLoad.load([{
    name: "StreamApp",
    files: [
        "/js/angular/includes/states.js",

Because of that, the first config is being executed twice. I think it is related to bug #41. Is there a solution for that? I've tried to do it

$ocLazyLoad.load([{
    name: "StreamApp2",
    files: [
        "/js/angular/includes/states.js",

And in states define the second streamapp but the state is not registered. :(

@ocombe
Copy link
Owner

ocombe commented Jul 23, 2014

Yes it's probably the same thing. I'll take a look at it tomorrow.

@citosid
Copy link
Author

citosid commented Jul 23, 2014

Thanks a lot. In the meantime I'll find another way.

ocombe added a commit that referenced this issue Jul 23, 2014
A new option has been added, you can use `reconfig: true` if you want to execute config block at each load of the module

Fixes #43
Fixes #41
@ocombe
Copy link
Owner

ocombe commented Jul 23, 2014

Fixed in 0.3.3 !

@citosid
Copy link
Author

citosid commented Jul 23, 2014

Excellent! It worked ;)

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