zoukankan      html  css  js  c++  java
  • AngularJS Best Practices: ng-include vs directive

    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.

  • 相关阅读:
    1. 加载文件的方法
    9. 位运算符
    8. 条件(条目,三元)运算符
    3. PHP比较运算符
    hdu3336 Count the string
    Codeforces Round #228 (Div. 2)
    hdu4288 Coder(线段树单点更新)
    hdu2852 KiKi's K-Number
    poj1195
    poj2299
  • 原文地址:https://www.cnblogs.com/zhangpengc/p/5097533.html
Copyright © 2011-2022 走看看