4

I am planning to develop my company's CRM (Customer Relationship Management) system in AngularJS. This system is not small, there are modules like customer CRUD, Shopping Cart, After-Sales Service, and so on.

As I noticed, usually an AngularJS has just one main "ng-app".

  1. Is there any problem to build more than on "ng-app" for a system (one for each CRM module)?

  2. What would be its pros and cons?

Edit 1: I am not planning to use more than one ng-app per HTML, but many (about 7) in the whole application.

Edit 2: The idea is create one Angular Module for each CRM module, for example:

customer.html
<html lang="en" ng-app="crmCustomer">
angular.module('crmCustomer', ['customers']);

sales.html
<html lang="en" ng-app="crmSales">
angular.module('crmSales', ['customers','cart','sales']);

afterSales.html
angular.module('crmAfterSales', ['customers', 'remittance']);
<html lang="en" ng-app="crmAfterSales">

wrenzi
  • 162
  • 1
  • 8
  • I don't understand why the down vote. Is it unclear or not useful? What can I do to make it better? – wrenzi May 05 '15 at 10:58
  • 1
    Hey Wrenzi check the following questions which are similar to the one you have asked.These might help you a) http://stackoverflow.com/questions/18571301/angularjs-multiple-ng-app-within-a-page b) http://stackoverflow.com/questions/19666816/multiple-ng-app-directives-on-a-page c) http://stackoverflow.com/questions/12860595/how-to-define-two-angular-apps-modules-in-one-page – Angular Learner May 05 '15 at 11:01
  • 1
    Hi Rao, thanks for your reply. There is a subtle difference between my question and the ones you posted. I am planning to use just one ng-app per HTML but many (about 7) in the whole application. – wrenzi May 05 '15 at 11:11

1 Answers1

3

I've found using multiple apps in one page is burdensome (as you can see in solutions linked by Amruth Rao) and rather creates issues than solves any.

Instead, I create a 'root' app and add the modules I need, ex.:

angular.module('crm', ['customers', 'cart', 'sales']);

Just make sure the components in those modules have different names, maybe by prefixs.

Bartłomiej Szypelow
  • 2,121
  • 15
  • 17
  • Hello Szypelow, thanks for your answer, it's very useful. My idea is almost it, the difference is that I would create one Angular Module for each CRM module, for example: `angular.module('crmCustomer', ['customers']);` customer.html ` ... ` `angular.module('crmSales', ['customers','cart','sales']); ` sales.html ` ... ` `angular.module('crmAfterSales', ['customers', 'remittance']); ` afterSales.html ` ... ` Are there any cons to it? – wrenzi May 05 '15 at 12:18
  • That's exactly what I did in one of the websites. We haven't got any issues with that so far. – Bartłomiej Szypelow May 06 '15 at 08:49