ng-include:

官网实例:

    <p>ng-include:</p>
<select ng-model="template" ng-options="t.name for t in templates">
<option value="">(blank)</option>
</select>
url of the template: <span>{{template.url}}</span>
<div>
<div ng-include="template.url"></div>
</div>
$scope.templates = [
{'name':'template1.html','url':'ngincludetemplate1.html'},
{'name':'template2.html','url':'ngincludetemplate2.html'}
];
$scope.template = $scope.templates[0];
ngincludetemplate1.html:
<p>content of ngincludetemplate1</p>
ngincludetemplate2.html:
<p>content of ngincludetemplate2</p>

选择的是template1.html时会显示ngincludetemplate1.html页面的内容:相当于<div ng-include=" 'ngincludetemplate1.html' "></div>

选择的是template2.html时会显示ngincludetemplate2.html页面的内容:相当于<div ng-include=" 'ngincludetemplate2.html' "></div>

也可以简单地写成如下形式:

<div ng-include=" 'ngIncludetemplate2.html' "></div>
<div ng-include="tpl"></div>
<div ng-include src="tpl"></div>
$scope.tpl = 'ngIncludetemplate2.html';

此处的值是字符串,所以直接在ng-include写值时要加上''(单引号),或者在js定义一个变量,ng-include引入值时引用变量名即可。

script:

    <div ng-include="'template1.html'"></div><!--直接引用id值(字符串类型)-->
<div ng-include src="'template2.html'"></div><!--src:直接引用id值(字符串类型)-->
<div ng-include="scriptTpl3"></div><!--引用变量,变量值是id值(字符串类型)-->
<div ng-include src="scriptTpl4"></div><!--src:引用变量,变量值是id值(字符串类型)-->
<script type="text/ng-template" id="template1.html">
使用script加载的模板,ng-include字符串
</script>
<script type="text/ng-template" id="template2.html">
使用script加载的模板,ng-include src字符串
</script>
<script type="text/ng-template" id="template3.html">
使用script加载的模板,ng-include变量
</script>
<script type="text/ng-template" id="template4.html">
使用script加载的模板,ng-include src变量
</script>
$scope.scriptTpl3 = 'template3.html';
$scope.scriptTpl4 = 'template4.html';

这里需要注意,type="text/ng-template"是指明这是ng模板,id属性是指实际使用模板时的一个引用,标签之间的内容才是实际的模板内容。而且,需要注意,id绝对不是URL,这个script标签绝对不会发出HTTP请求。 
实际应用模板时候,使用ID属性,即可从内存中获取对应数据。

参考:https://www.zybuluo.com/bornkiller/note/6023

最新文章

  1. WIN10下安装HBASE教程
  2. cocoapods安装
  3. HTML的页面IE注释
  4. centos ADSL 拨号上网设置
  5. Java 集合系列04之 fail-fast总结(通过ArrayList来说明fail-fast的原理、解决办法)
  6. Nutch2.x
  7. 。net新人报道
  8. &lt;转&gt;错误 x error LNK1104: 无法打开文件“E:\xxxx\Debug\xxxx.exe”
  9. mongo数据库的导入导出
  10. 下拉框分组显示optgroup
  11. tomcat的OutOfMemoryError(PermGen space)解决方法
  12. C#学习笔记---基础入门(二)
  13. google模拟各种Android手机浏览器方法
  14. javascript中,数组常用的方法有哪些?
  15. 自己定义flash的宽和高
  16. 一款超好用轻量级JS框架——Zepto.js(下)
  17. Oracle问题之ORA-12560TNS:协议适配器错误
  18. PXC5.7(Percona XtraDB Cluster)+HAproxy+Keepalived 集群部署
  19. PS绘制扁平化风格相机镜头UI图标
  20. cmake:善用find_package()提高效率暨查找JNI支持

热门文章

  1. CSS white-space 属性
  2. sql server 2012 数据引擎任务调度算法解析(上)
  3. Linux下TomcatVM参数修改:Native memory allocation (mmap) failed to map 3221225472 bytes for committing reserved memory.
  4. MVC MemeberShip vs. Asp.net Identity
  5. Python学习记录day4
  6. 2016.11.6 night NOIP模拟赛 考试整理
  7. 一段拼装sql的小代码
  8. TortoiseSVN 中 一个 Merge revisions to.. 小坑
  9. LeetCode-66-Plus One
  10. nginx.conf中配置laravel框架站点