add angular module to main module runtime using reuqirejs

26 views
Skip to first unread message

hardik Patel

unread,
Apr 5, 2016, 12:53:43 AM4/5/16
to AngularJS
I am working on Angular Application. I have a application with multiple modules. Application structure is like i have a Main Module and at run time i want to inject sub modules in main module.

Please help me out.

Thanks in Advance

Ashish Kumar

unread,
Apr 5, 2016, 1:28:46 AM4/5/16
to ang...@googlegroups.com
Hi Hardik,

  According to your requirement ,I am not sure ,there is a way to do this by angular because you need to load your all modules in browers .Try this..(might work)


window.SubModuleDependencies = [];//add this before you do anything else

// at the end of each module file:
window.SubModuleDependencies.push('yourmoduleName')

// after all that, at the app definition:
app = angular.module("app", SubModuleDependencies
)

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
Regards,
Ashish Kumar

Vaibhav Gupta

unread,
Apr 5, 2016, 1:32:13 AM4/5/16
to AngularJS
Hi,

I am assuming that you don't want to inject sub modules to main module, rather you want to load modules dynamically along with main module. You can manually bootstrap your application using a code like the following:

if(/*some condition*/){
 angular
.bootstrap(document, ['mainModule','module1']);
}
else{
 angular
.bootstrap(document, ['mainModule','module2']);
}


Please refer to the documentation here:


Does this fulfil your requirement?

Regards,

Vaibhav Gupta

hardik Patel

unread,
Apr 5, 2016, 2:38:55 AM4/5/16
to ang...@googlegroups.com
Actually, i want to add sub modules in main module after bootstrap.

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/GznpwAczego/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.

Vaibhav Gupta

unread,
Apr 5, 2016, 2:42:03 AM4/5/16
to ang...@googlegroups.com
Hi,

Can you share a use case for dynamically injecting modules? A plunker will be helpful.

Regards,

Vaibhav Gupta
Reply all
Reply to author
Forward
0 new messages