directive VS ng-include

General html block can be reused in two ways: put into a directive as template, or simply include it with ng-include.

There are two common points between directive and ng-include:

(1) They can both be resused

(2) They can both have their own controller

But directive is more flexible and stronger than ng-include, because:

    (1) Scope for directive is isolate, functions in parent scope can not be used in directive except it’s passed into directive.

While, functions in parent scope can be used directively used in ng-include which might cause mass.

(2) Values can all be passed into directive and ng-include, but ng-include can only accept init values, directive can accept changing values by accepting parameters. Which means directive can react with DOM, ng-include can not.

(3) Different functions(logic) according to different users can be passed into directive, function in ng-include can only be fixed(which should be in the controller for this ng-include to make the functionality also reusable instead of duplicate every time in its users).

There‘s one advantage that ng-include holds:

(1) As template for ng-include is fixed, browser doesn’t need to compile template for ng-include, so template loading for ng-include is faster than directive.

So, when one block of html code is reusable, if it‘s a fixed paragraph or the logic in it is fixed(eg. showing a list of constant), then ng-include should be a good choice, otherwise, directive is a better flexible choice.

时间: 2024-12-22 04:25:04

directive VS ng-include的相关文章

Part 16 ng include directive in AngularJS

ng-include directive is used to embed an HTML page into another HTML page. This technique is extremely useful when you want to reuse a specific view in multiple pages in your application. The value of ng-include directive can be the name of the HTML

走进AngularJs(二) ng模板中常用指令的使用方式

通过使用模板,我们可以把model和controller中的数据组装起来呈现给浏览器,还可以通过数据绑定,实时更新视图,让我们的页面变成动态的.ng的模板真是让我爱不释手.学习ng道路还很漫长,从模板开始入手是个不错方式,因为这部分内容相对简单好理解,而且是视图层的东西,大家都喜欢可以立马看得见的东西嘛.本篇我将搜罗模板中的常用指令一一测试,了解其使用方法,有点像背单词的感觉,会比较枯燥.不过对于初学,这样的枯燥是必须要经历的,开始~ 一.模板中可使用的东西及表达式 模板中可以使用的东西包括以下

angularjs中常用的ng指令介绍【转载】

原文:http://www.cnblogs.com/lvdabao/p/3379659.html 一.模板中可使用的东西及表达式 模板中可以使用的东西包括以下四种: 指令(directive).ng提供的或者自定义的标签和属性,用来增强HTML表现力. 标记(markup).即双大括号{{}},可将数据单向绑定到HTML中. 过滤器(filter).用来格式化输出数据. 表单控制.用来增强表单的验证功能. 其中,指令无疑是使用量最大的,ng内置了很多指令用来控制模板,如ng-repeat,ng-

angularjs 学习笔记 -----结构定义

1.  Module使用方法 var APP =angular.module('fontApp',['ngResource', 'ngRoute', 'ngSanitize']); APP为定义的别名,之后的调用都应尽量使用该别名 'fontApp' ng-app="fontApp" 新版本angular中route被分离出来,各个被使用的Providerdou需要在此处声明. 大型应用应该拆分模块来做,先定义一个服务模块,然后再加载它 angular.module('xmpl.ser

JSP学习初体验

JSP简介: 1)JSP--Java Server Pages 2)拥有servlet的特性与优点(本身就是一个servlet) 3)直接在HEML中内嵌JSP代码 4)JSP程序由JSP Engine先将它转换成servlet代码,接着将它编译成类文件载入执行 5)只有当客户端第一次请求执行JSP时,才需要将其转换.编译 JSP的优点: 1)优良的性能 优于CGI.PHP.ASP 2)平台无关性 操作系统无关,web服务器无关 3)可扩展性 tag的扩展机制,简化页面开发 JSP编程--基本语

angularjs学习总结 详细教程(转载)

1 前言 前端技术的发展是如此之快,各种优秀技术.优秀框架的出现简直让人目不暇接,紧跟时代潮流,学习掌握新知识自然是不敢怠慢. AngularJS是google在维护,其在国外已经十分火热,可是国内的使用情况却有不小的差距,参考文献/网络文章也很匮乏.这里便将我学习AngularJS写成文档,一方面作为自己学习路程上的记录,另一方面也给有兴趣的同学一些参考. 首先我自己也是一名学习者,会以学习者的角度来整理我的行文思路,这里可能只是些探索,有理解或是技术上的错误还请大家指出:其次我特别喜欢编写小

Nginx 负载均衡

原文地址:http://nginx.com/resources/admin-guide/load-balancer/ Nginx Load Balancing nginx 负载均衡 This section describes how to use NGINX and NGINX Plus as a load balancer. 本章将讨论如何使用Nginx和Nginx加做负载均衡器. In This Section 本章包括 Load balancing overview 负载均衡概览 Pro

JSP学习笔记

一,JSP简介 JSP---Java Server Pages 拥有servlet的特性与优点(本身就是一个servlet) 直接在HTML中内嵌JSP代码 JSP程序由JSP Engine先将它转换成Servlet代码,接着将它编译成类文件载入执行 只有当客户端第一次请求JSP时,才需要将其转换.编译 优点: 优良的性能 优于CGI,PHP,ASP 平台无关性 操作系统无关,Web服务器无关 可扩展性 tag的扩展机制,简化页面开发 二,JSP基本语法 JSP传统语法 Declaration

AngularJS理论基础

AngularJS理论基础 AngularJs是一个用于设计动态web应用的结构框架. 它是一个框架,不是类库,是像EXT一样提供一整套方案用于设计web应用.它不仅仅是一个javascript框架,因为它的核心其实是对HTML标签的增强.使你能够用标签完成一部分页面逻辑,具体方式就是通过自定义标签.自定义属性等,这些HTML原生没有的标签/属性在ng中有一个名字:指令(directive).web应用能为用户提供丰富的操作,能够随用户操作不断更新视图而不进行url跳转.ng官方也声明它更适用于

AngularJS开发指南7:AngularJS本地化,国际化,以及兼容IE低版本浏览器

AngularJS本地化,国际化 国际化,简写为i18n,指的是使产品快速适应不同语言和文化. 本地化,简称l10n,是指使产品在特定文化和语言市场中可用. 对开发者来说,国际化一个应用意味着将所有的文字和其他因地区而异的数据从应用中抽离出来. 本地化意味着为这些抽离的数据和文字提供翻译和转变成本地的格式. 目前,AngularJS支持日期,数字和货币的国际化和本地化. 另外,AngularJS还通过ngPluralize指令支持本地多元化. 所有的AngularJS本地化组件都依赖于$loca