博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AngularJS Best Practices: ng-include vs directive
阅读量:4921 次
发布时间:2019-06-11

本文共 1126 字,大约阅读时间需要 3 分钟。

For building an HTML template with reusable widgets like header, sidebar, footer, etc. Basically the main content is the central DIV which will have its content varying between routes, header and footer will be almost always the same, sidebar can vary in certain pages.

Based on the your page structure, at least for headers and footers you do not need to use directives, there would be only single rendering for these controls. Standard ng-include with a partial and maybe a linked controller would do. Remember ng-include itself is a directive.

Directive would be useful where you want a component that needs to used across pages, your headers and footer nav do not fit this bill as there is a single instance of these elements on the page.

But I prefer directives because ng-include only breaks down the view part into smaller modules. By using directives, even if it is used only once, you still nicely modularize your page into smaller independent components. Markup of the parent page looks much nicer and you don't have to clutter your controller with more methods.

 

转载于:https://www.cnblogs.com/zhangpengc/p/5097533.html

你可能感兴趣的文章
DDD的思考
查看>>
类型转换及返回json对象的问题
查看>>
模拟题 找出不能拼凑的最小数
查看>>
ivew实现table的编辑保存追加删除
查看>>
poj 1904(强连通分量+输入输出外挂)
查看>>
Ubuntu重启关机命令使用
查看>>
第5章 不要让线程成为脱缰的野马(Keeping your Threads on Leash) ---干净的终止一个线程...
查看>>
shell $() vs ${}
查看>>
实现Serializable的类 的serialVersionUID的作用和生成
查看>>
PHP $_SERVER详解
查看>>
shell脚本大小写转换
查看>>
hdu4699-Editor
查看>>
正则小全
查看>>
Nginx二级目录自动加斜杠
查看>>
iOS开发技巧——关闭Autoresizing开启Autolayout
查看>>
JSP学习笔记(4)-Javabean
查看>>
乐观锁和悲观锁的区别
查看>>
搜索引擎算法研究专题二:HITS算法及其衍生算法分析
查看>>
C语言 内存四大存储区域
查看>>
浏览器兼容性
查看>>