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

Determine if module is already loaded? #79

Closed
rmunch opened this issue Nov 4, 2014 · 4 comments
Closed

Determine if module is already loaded? #79

rmunch opened this issue Nov 4, 2014 · 4 comments

Comments

@rmunch
Copy link

rmunch commented Nov 4, 2014

I'm curious if there's a way to check if a module has already been loaded? I see there's a private function moduleExists() that does this, but it's not accessible from outside the module. Maybe a new method could be exposed to support this, e.g. $ocLazyLoad.isLoaded('my.module')?

My use case is that I need to recompile a directive template after lazy-loading a module containing some UI components. I'd like to set it up so it only does this if the module has not yet loaded.

Thanks!

@ocombe
Copy link
Owner

ocombe commented Nov 4, 2014

Well there is an undocumented function named getModules that returns an array with the list of the loaded modules, you could use it with indexOf:

if($ocLazyLoad.getModules().indexOf('my.module') > -1) {
  // ...
}

Otherwhise you can use the same thing that I do in my lib:

var isLoaded = false;
try {
        isLoaded = angular.module(moduleName);
    } catch(e) {
        if(/No module/.test(e) || (e.message.indexOf('$injector:nomod') > -1)) {
            isLoaded = false;
        }
    }

But if you want I could add a isLoaded function, yes.

@ocombe ocombe added the question label Nov 4, 2014
@kamilbrk
Copy link

kamilbrk commented Nov 4, 2014

+1 for making it available outside.

I was looking for the same thing last week and come across several try/catch based solutions. Your internal method with additional regex inside was the prettiest to be fair.

@ocombe
Copy link
Owner

ocombe commented Nov 5, 2014

If it can be useful, I don't see why not.
I'll do it when I have the time. If you want to have it faster, you can do a PR :)

@ocombe ocombe closed this as completed in 364c9e9 Nov 9, 2014
@ocombe
Copy link
Owner

ocombe commented Nov 9, 2014

Available in master. I'll make a new release soon.

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

No branches or pull requests

3 participants