我打算使用angular JS来完成我的UI工作.我已经查找了如何做到这一点的例子,这一切都很好,但我不确定…
NG-应用
1-我应该每个应用程序使用一个还是每页一个或者无关紧要?
2-如果我决定何时无所谓?
我看到在html标签上使用它的示例以及在div中使用的其他一些示例,但我不确定如何决定可能是由于对框架缺乏了解.
解决方法
Only one AngularJS application can be auto-bootstrapped per HTML
document. The firstngApp
found in the document will be used to define
the root element to auto-bootstrap as an application. To run multiple
applications in an HTML document you must manually bootstrap them
using angular.bootstrap instead. AngularJS applications cannot be
nested within each other.
您可以定义多个模块,这些模块之间可能存在依赖关系.
angular.module('Core',[]); angular.module('Module1',['Core']); angular.module('Module2',['Core']);
在每页上使用适当的模块.
你应该有多少个模块?这取决于您的应用程序的复杂程度以及您希望如何构建它.
所以,是的,如果你刚开始有角度,我会说不要太费心.将所有内容放在一个模块中,然后重构.关于角度还有其他更棘手的部分你应该关注.
另外,您可能想看看这个style guide.
编辑:
为了清楚起见,我们的想法是使用一个ng-app并选择适当的模块来引导应用程序,具体取决于您站点的区域(如果您构建一个只有一个模块的单页应用程序,则不适用负责引导您的应用程序)