Skip to content

[Q] Conditional loading external module #147

@alex88

Description

@alex88

Hi,

I've an angular app that's loaded in all pages of my website. On just one page, I've to load another module as a dependency of my app since there's a directive on that page handled by this additional module.

I've 2 files, one with angular and all its dependencies (plus my app) and another with the secondary module.

At first I was trying this way (coffeescript):

try
  angular.module 'secondmodule'
  angular.module 'myapp', ['secondmodule']
catch
  angular.module 'myapp', []
end

But since during the parsing of the first file secondmodule is not defined it throws the exception.
Leaving just angular.module 'myapp', ['secondmodule'] works on the page where the second module is included (maybe the check of modules is done during the bootstrap so both files are loaded) but throws the exception in all the other pages.

I've then tried to leave just angular.module 'myapp', [] and in the run stage do:

$ocLazyLoad.load('secondmodule')

that doesn't throw any exception but the directive inside my app isn't catched by the second module.

Is it possible to do this with ocLazyLoad?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions