AngularJS directive简述
转自:http://segmentfault.com/q/1010000002400734
官方API:http://docs.angularjs.cn/api/ng/service/$compile
一个民间详细介绍:http://blog.51yip.com/jsjquery/1607.html
问:
angular.module('docsTransclusionExample', [])
.controller('Controller', ['$scope', function($scope) {
$scope.name = 'Tobias';
}])
.directive('myDialog', function() {
return {
restrict: 'E',
transclude: true,
scope: {},
templateUrl: 'my-dialog.html',
link: function (scope, element) {
scope.name = 'Jeff';
}
};
});
答:
1.restrict
E: 表示该directive仅能以element方式使用,即:<my-dialog></my-dialog>
A: 表示该directive仅能以attribute方式使用,即:<div my-dialog></div>
EA: 表示该directive既能以element方式使用,也能以attribute方式使用 2.transclude
你的directive可能接受页面上的其他html内容时才会用到,建议你先去掉该参数。有些高阶了。 3.scope
当你写上该属性时,就表示这个directive不会从它的controller里继承$scope对象,而是会重新创建一个。 4.templateUrl
你的directive里的html内容 5.link
可以简单理解为,当directive被angular 编译后,执行该方法
这里你说的没错,link中的第一个参数scope基本上就是你说的上面写的那个scope。
element简单说就是$('my-dialog')
attrs是个map,内容是你这个directive上的所有属性,例如:你在页面上如果这样写了directive:
<my-dialog type="modal" animation="fade"></my-dialog>
那attrs就是:
{
type: 'modal',
animation: 'fade'
}
AngularJS directive简述的更多相关文章
- 学习AngularJs:Directive指令用法
跟我学AngularJs:Directive指令用法解读(上) http://blog.csdn.net/evankaka/article/details/51232895 跟我学AngularJs: ...
- angularjs directive 实例 详解
前面提到了angularjs的factory,service,provider,这个可以理解成php的model,这种model是不带html的,今天所说的directive,也可以理解成php的mo ...
- 学习AngularJs:Directive指令用法(完整版)
这篇文章主要学习AngularJs:Directive指令用法,内容很全面,感兴趣的小伙伴们可以参考一下 本教程使用AngularJs版本:1.5.3 AngularJs GitHub: http ...
- Angularjs directive全面解读(1.4.5)
说到Angularjs directive即指令,可以这么说Angularjs的灵魂就是指令,学会Angularjs指令那么你的Angularjs的武功就修炼了一半了,当然这只是鄙人的一点点独到见解, ...
- angularjs directive (自定义标签解析)
angularjs directive (自定义标签解析) 定义tpl <!-- 注意要有根标签 --> <div class="list list-inset" ...
- 步入angularjs directive(指令)--点击按钮加入loading状态
今天我终于鼓起勇气写自己的博客了,激动与害怕并存,希望大家能多多批评指导,如果能够帮助大家,也希望大家点个赞!! 用angularjs 工作也有段时间了,总体感觉最有挑战性的还是指令,因为没有指令的a ...
- AngularJS Directive 隔离 Scope 数据交互
什么是隔离 Scope AngularJS 的 directive 默认能共享父 scope 中定义的属性,例如在模版中直接使用父 scope 中的对象和属性.通常使用这种直接共享的方式可以实现一些简 ...
- [译]angularjs directive design made easy
原文: http://seanhess.github.io/2013/10/14/angularjs-directive-design.html AngularJS directives很酷 Angu ...
- AngularJS directive 指令相关记录
.... .directive('scopeDemo',function(){ return{ template: "<div class='panel-body'>Name: ...
随机推荐
- centos7.0安装redis扩展
1.下载 下载地址:https://github.com/phpredis/phpredis/ 文件名:phpredis-develop.zip 文件下载成功后,上传至/usr/local 2.安装 ...
- 2218 补丁vs错误
2218 补丁vs错误 1999年CTSC国家队选拔赛 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 大师 Master 题解 题目描述 Description 错 ...
- 爬虫入门【3】BeautifulSoup4用法简介
快速开始使用BeautifulSoup 首先创建一个我们需要解析的html文档,这里采用官方文档里面的内容: html_doc = """ <html>< ...
- 如何实现模拟器(CHIP-8 interpreter) 绝佳杰作.
转自 http://www.multigesture.net/articles/how-to-write-an-emulator-chip-8-interpreter/ How to write an ...
- 算法设计 mac 字符串 标识 n维度 2 3维度 字符串 标识值 特征值
基向量
- JDBC详解1
JDBC详解1 JDBC整体思维导图 JDBC入门 导jar包:驱动! 加载驱动类:Class.forName("类名"); 给出url.username.password,其中u ...
- python中的一些坑(待补充)
函数默认参数使用可变对象 def use_mutable_default_param(idx=0, ids=[]): ids.append(idx) print(idx) print(ids) use ...
- Hadoop1.x Shell命令
refer to http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_shell.html FS Shell 调用文件系统(FS)Shell命令应使用 bin/h ...
- java 泛型的简单使用
effecttive java一直推荐使用泛型,简单的看了一下泛型的使用 package cn.com.fzk; import java.util.ArrayList; import java.uti ...
- 通过设置PHPSESSID保存到cookie实现免登录
$cookieParams = session_get_cookie_params(); session_set_cookie_params( 3600,// 设置sessionID在cookie中保 ...