angular 自定义指令 link
function link(scope, element, attrs) { ... } where:
scopeis an Angular scope object.elementis the jqLite-wrapped element that this directive matches.attrsis a hash object with key-value pairs of normalized attribute names and their corresponding attribute values.
<div ng-controller="Controller">
Date format: <input ng-model="format"> <hr/>
Current time is: <span my-current-time="format"></span>
</div> angular.module('docsTimeDirective', [])
.controller('Controller', ['$scope', function($scope) {
$scope.format = 'M/d/yy h:mm:ss a';
}])
.directive('myCurrentTime', ['$interval', 'dateFilter', function($interval, dateFilter) { function link(scope, element, attrs) {
var format,
timeoutId; function updateTime() {
//format从watch方法里获得
element.text(dateFilter(new Date(), format));
} scope.$watch(attrs.myCurrentTime, function(value) {
format = value;//value:M/d/yy h:mm:ss a
updateTime();
}); element.on('$destroy', function() {
$interval.cancel(timeoutId);
}); // start the UI update process; save the timeoutId for canceling
timeoutId = $interval(function() {
updateTime(); // update DOM
}, );
} return {
link: link
};
}]);
angular 自定义指令 link的更多相关文章
- angular 自定义指令 link or controller
Before compilation? – Controller After compilation? – Link var app = angular.module('plunker', []); ...
- Angular自定义指令(directive)
angular自定义指令,意我们可以通过angula自己定义指令,来实现我们的特殊要求,为所欲为,一支穿云箭,千军万马来相见 多少年的老规矩了,先看代码: <!DOCTYPE html> ...
- angular 自定义指令详解 Directive
在angular中,Directive,自定义指令的学习,可以更好的理解angular指令的原理,当angular的指令不能满足你的需求的时候,嘿嘿,你就可以来看看这篇文章,自定义自己的指令,可以满足 ...
- angular自定义指令命名的那个坑
Directive 先从定义一个简单的指令开始. 定义一个指令本质上是在HTML中通过元素.属性.类或注释来添加功能.AngularJS的内置指令都是以ng开头,如果想自定义指令,建议自定义一个前缀代 ...
- angular 自定义指令 directive transclude 理解
项目中断断续续的用了下angular,也没狠下心 认真的学习.angular 特别是自定义指令这块 空白. transclude 定义是否将当前元素的内容转移到模板中.看解释有点抽象. 看解释有点抽象 ...
- Angular自定义指令directive:scope属性
在AngularJS中,除了内置指令如ng-click等,我们还可以自定义指令.自定义指令,是为了扩展DOM元素的功能.代码中,通过指定directive中的restrict属性,来决定这个指令是作为 ...
- Angular17 Angular自定义指令
1 什么是HTML HTML文档就是一个纯文本文件,该文件包含了HTML元素.CSS样式以及JavaScript代码:HTML元素是由标签呈现,浏览器会为每个标签创建带有属性的DOM对象,浏览器通过渲 ...
- angular自定义指令
1.在directive文件下创建指令的js文件 通常自定义指令需要声明模块(注意定义指令时, js内部指令名称需采用 aaAaBb驼峰的命名方式 html中使用的是aa-aa-bb) e.g (f ...
- angular自定义指令 repeat 循环结束事件;limitTo限制循环长度、限定开始位置
1.获取repeat循环结束: 自定义指令: .directive('repeatFinish', function () { return { link: function (scope, elem ...
随机推荐
- JMX初体验
这些天在看<How Tomcat Works>这本书.里面讲到了JMX的内容.对我来说是个新知识点. JMX--Java Management Extensions,即Java管理扩展,是 ...
- Qt 窗口属性简介之Qt::WA_DeleteOnClose
一.简述 今天介绍一个简单的窗口属性——Qt::WA_DeleteOnClose. 在正常创建窗口后,我们一般会调用close()方法来关闭窗口,这里我们看一下Q助手中关于close()方法的介绍. ...
- 其他常用HTML 片段
1.input placeholder 文字居中 字体大小+上下padding值等于设计稿宽度 设计稿中总高度为86px padding:27px 0;font-size:30px; 2.英文 ...
- MVC分页控件之二,为IQueryable定义一个扩展方法,直接反回PagedList<T>结果集(转)
namespace Entity { public interface IPagedList { /// <summary> /// 记录数 /// </summary> in ...
- partial类与[MetadataType(typeof(类名))]有什么区别?
在MVC的Model中,我们可以定义很多与视图相关的元数据,这些元数据对我们开发视图起着相当重要的作用,特别是在数据验证方面.这些元数据一般情况下我们是不会定义在业务实体(或持久化实体)上面,所以很多 ...
- 提取日志中的json请求发送到另外一台机器
将日志中的json请求提取,并且发送到另外一个机器上: for i in ` cat impression.log.2016-04-08-10 |awk -F"\t" ' {pri ...
- Java学习-037-JavaWeb_006 -- JSP 动作标识 - include
这个动作是指在当前的页面中包含一个或多个 JSP 页面或者 HTML 文件,语法:<jsp:include file="../jsp/login.jsp" flush=&qu ...
- imx6 uboot lcd
本文记录imx6 uboot中关于lcd初始化的过程. uboot中相关的文件: cpu/arm_cortexa8/start.S lib_arm/board.c board/freescale/mx ...
- XLST
xlst转换 // 读入源请求和mapping配置 StreamSource xmlSource = new StreamSource(new InputStreamReader(new ByteAr ...
- jquery的hover mouseover mouseout mouseenter mouseleave的区别
jquery的hover mouseover mouseout mouseenter mouseleave的区别 1.mouseover mouseout mouseover - 鼠标指针经过任何子元 ...