【问题标题】:It is a good idea create more than one ng-app in AngularJS application?在 AngularJS 应用程序中创建多个 ng-app 是个好主意吗?
【发布时间】:2015-05-05 10:51:17
【问题描述】:

我计划在 AngularJS 中开发我公司的 CRM(客户关系管理)系统。这个系统不小,有客户CRUD、购物车、售后服务等模块。

我注意到,AngularJS 通常只有一个主要的“ng-app”。

  1. 除了为系统构建“ng-app”(每个 CRM 模块一个)之外,还有什么问题吗?

  2. 它的优缺点是什么?

编辑 1:我不打算在每个 HTML 中使用多个 ng-app,但在整个应用程序中使用多个(大约 7 个)。

编辑 2:想法是为每个 CRM 模块创建一个 Angular 模块,例如:

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">

【问题讨论】:

标签: angularjs


【解决方案1】:

我发现在一个页面中使用多个应用程序很麻烦(正如您在 Amruth Rao 链接的解决方案中看到的那样),而且会产生问题而不是解决任何问题。

相反,我创建了一个“根”应用程序并添加了我需要的模块,例如:

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

只需确保这些模块中的组件具有不同的名称,可能是前缀。

【讨论】:

  • 您好 Szypelow,感谢您的回答,它非常有用。我的想法差不多,不同的是我会为每个CRM模块创建一个Angular Module,例如:angular.module('crmCustomer', ['customers']);customer.html<html lang="en" ng-app="crmCustomer"> ... angular.module('crmSales', ['customers','cart','sales']); sales.html<html lang="en" ng-app="crmSales"> ... angular.module('crmAfterSales', ['customers', 'remittance']); afterSales.html@987654327 @ 有什么缺点吗?
  • 这正是我在其中一个网站中所做的。到目前为止,我们还没有遇到任何问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-17
  • 1970-01-01
相关资源
最近更新 更多