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 ...
随机推荐
- C/C++ 排序&&查找算法(面试)
一.排序 1.冒泡排序 void BubbleSort(int array[],int n) { ; ; ; ; ;i<n - ;i++) /*外循环控制排序的总趟数*/ { flag = ; ...
- oracle用户创建及权限设置
权限: create session create table unlimited tablespace connect resource dba 例: #sqlplus /nolog SQL> ...
- JS:checkFrom对输入框和文本框的判断总结
天看了老东家的一个专题页面,发现里边的checkFrome.js收集了很多对文本框的判断,非常有用收藏一下.其中包含了:1.页面截取字符串2.文本框最大长度限制3.判断必须是数字和字母的组合4.判断是 ...
- RTSP交互命令简介及过程参数描述
目录 [hide] 1 RTSP消息格式 2 简单的rtsp交互过程 3 rtsp中常用方法 3.1 OPTION 3.2 DESCRIBE 3.3 SETUP 3.4 PLAY 3.5 PAUSE ...
- [LeetCode]题解(python):091 Decode Ways
题目来源 https://leetcode.com/problems/decode-ways/ A message containing letters from A-Z is being encod ...
- sell- 获取邮箱的后缀
1. public static void main(String[] args) { System.out.println(getEmailSuffix("jim_chen28270@16 ...
- Web service是什么?
原文:http://www.ruanyifeng.com/blog/2009/08/what_is_web_service.html 我认为,下一代互联网软件将建立在Web service(也就是&q ...
- 创建数据库和表的SQL语句
创建数据库的SQL语句: 1 create database stuDB 2 on primary -- 默认就属于primary文件组,可省略 3 ( 4 /*--数据文件的具体描述--*/ 5 n ...
- iOS项目的目录结构和开发流程(Cocoa China)
目录结构 AppDelegate Models Macro General Helpers Vendors Sections Resources 一个合理的目录结构首先应该是清晰的,让人一眼看上去 ...
- malloc函数和其他内存分配函数
1. 需要包含头文件:#i nclude 或 #i nclude 函数声明(函数原型): void *malloc(int size); 说明:malloc 向系统申请分配指定size个字节的内存空间 ...