【发布时间】:2014-02-19 22:32:30
【问题描述】:
我是 AngularJS 的新手,正在集思广益如何在我的应用程序中命名模块。
一个限制是我需要能够在不使用 iframe 的情况下将我的 Angular 应用程序嵌入到第三方网站(也可能使用 Angular)内的占位符 div 中。因此,我不能简单地创建没有命名空间的模块,例如 angular.module('users'),因为这可能与第三方应用程序中已经定义的任何“用户”模块发生冲突。
我来到了以下组织:
angular.module('mycompany.productname', [
'ngRoute',
'mycompany.productname.forms',
'mycompany.productname.users',
'mycompany.productname.services'
]);
angular.module('mycompany.productname.forms').controller('formEditController', ['$scope', function($scope) { ...
angular.module('mycompany.productname.users').controller('userAccountController', ['$scope', function($scope) { ...
angular.module('mycompany.productname.users').controller('userLoginController', ['$scope', function($scope) { ...
angular.module('mycompany.productname.services').service('forms', ['$scope', function($scope) { ...
考虑到我上面的限制,有没有更常见的解决方案?
【问题讨论】:
-
看起来不错。我喜欢非常相似地命名事物:)
-
我们为什么要投票结束这个问题?对你们这些人来说还不够客观吗?观看此问题在接下来的 4 个月内获得 1,000 次观看。
标签: javascript angularjs namespaces