当使用自定义指令VS UI视VS NG-包括在AngularJS应用程序? [英] When to use custom directive vs ui-view vs ng-include in an AngularJS application?
问题描述
我建立一个大型的,复杂的应用AngularJS(认为ERP系统)。我有一个很难决定何时适合使用用户界面视图
, NG-包括
或自定义指令+ templateURL
。
I am building a large, complex AngularJS application (think ERP system). I am having a hard time deciding when it is appropriate to use ui-view
, ng-include
or a custom directive + templateURL
.
我给几个具体的例子给你们一些帮助。
I will give a few concrete examples to give y'all something to work with.
- 是整个应用程序的所有URL中使用,但包括一个复杂的AJAX自动提示/下拉搜索框的导航菜单。
- 一个简单的HTML页脚是整个应用程序 的所有URL相同
- 的页眉和页脚之间走在了内容领域。
- 的依偎内容区域内(如和编辑个人资料的形式,或用户仪表盘)的单个组件
- 模式对话框
- A navigation menu that is used across all URLs of the application but includes a complex AJAX autosuggest/dropdown search box.
- A simple HTML footer that is the same across all URLs of the application
- The content areas that go in between the header and footer.
- The individual components that are nestled within the content area (such as and "Edit Profile" form, or user dashboard)
- Modal dialogs
什么是最好的做法是什么?
推荐答案
对于任何大型或复杂的应用程序,我建议尽可能多的code的组织为可重用的定制指令越好。自定义指令将允许您利用最大可重用性角度指令,并尽量减少当你在内置指令只能依靠存在的重复HTML。
For any large or complex application, I would suggest organizing as much of your code into re-usable custom directives as possible. Custom directives will allow you to leverage angular directives for maximum re-usability and minimize the repetitive HTML that exists when you rely only on built-in directives.
UI视图适合换出控制器和视图动态地根据不同的路线。如果你的应用程序的功能,其中每个视图和控制器的组合是自包含的,然后使用用户界面视图与路线是有道理的。
UI views are appropriate for swapping out controllers and views dynamically depending on the route. If you have application functionality where each view and controller combination is self-contained, then using a ui-view with routes makes sense.
这篇关于当使用自定义指令VS UI视VS NG-包括在AngularJS应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!