0

I am trying to inject angular module dynamically after some event as -

app.requires.push('projects');
console.log(app.requires);

I am referring to this link How to inject modules to main Angular app module on the fly to inject the module on occurrence of an event.

I have created a plunkr for the complete poc I have created. So on app.requires call it actually pushes projects module as dependency however when I click on link navigating to states defined inside the projects module, it logs an error stating Could not resolve 'projects.login' from state ''. Although these links work if I inject to module at the start only like guides module.

PS: Loading of project module happens upon clicking of button in index route.

2
  • 2
    app.requires.push('projects') will take effect if the app will be re-bootstrapped You can't add new modules to already bootstrapped app, Angular needs to be thoroughly patched to make this possible (something that ocLazyload does). It isn't clear why loadScript2 in your example should be loaded dynamically, there is a good chance that you have XY problem. Commented Feb 8, 2017 at 11:30
  • Cool..thanks for mentioning re-bootstrapping of the app. I missed that part. its working fine now. Also problem is a bit different and I can't put complete code here. Anyways it is fixed and I will keep the plunkr alive for anyone visiting it in future. Commented Feb 8, 2017 at 14:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.