angular自定义指令
来源:互联网 发布:淘宝打折怎么设置 编辑:程序博客网 时间:2024/06/10 03:56
angular自定义指令
angularJS 中内置了很多指令,但是有时候这些内置的指令满足不了我们的需求,这时候我们就需要自己定义指令,angular中提供了自定义的指令的方法,使用关键字directive,下面介绍一下他的参数:
指令的原理:1.加载 加载angular.js,找到ng-app之后,确定应用的边界。2.编译 遍历DOM,找到所有指令,根据指令中的template、replace和transclude转换DOM结构,如果存在compile函数就调用。3.链接 对每个指令操作link函数,link函数一般用来操作DOM,绑定事件监听器。> 注:自定义指令的名称不能采用驼峰命名法下面是示例:<h1 apdir1>这是装饰型指令</h1><h2 apdir2>这是组件型指令</h2><apdir2></apdir2><div apdir3>保留这几个文字</div> var app = angular.module('app',[]);//装饰性指令app.directive('apdir1',function(){ return { link:function(scope,ele,attrs){ ele.on('mouseover',function(){ ele.css({'color':'red'}) }).on('mouseout',function(){ ele.css({'color':'green'}) }) } }});//组件性指令app.directive('apdir2',function(){ return { //替换指令所在的标签,以模板代替,模板必须有一个根节点 replace: true, template:'<h4>hello</h4>', //指令使用的类型 E:作为标签使用 A:作为属性使用 C:作为class类名使用 D:作为注释使用 restrict:'EACM', //保留使用指令的标签内部的元素。 transclude: true }});app.directive('apdir3',function(){ return { //保留使用指令的标签内部的元素。 transclude: true, replace: true, template:'<h4>hello<div ng-transclude></div></h4>', restrict:'EACM', }})
阅读全文
0 0
- angular 自定义指令
- angular js自定义指令
- Angular自定义指令(进阶)
- angular自定义指令
- 创建angular自定义指令
- Angular --- 自定义指令更新
- angular 自定义指令
- angular自定义指令templateUrl
- Angular 自定义指令详解
- 一,Angular自定义指令
- Angular自定义指令
- angular自定义指令详解
- angular自定义指令
- angular.js自定义指令
- angular 自定义指令命名
- angular指令和自定义指令
- angular 自定义指令参数详解
- Angular自定义指令(初级)
- angularJs中的jqLite
- vue内置指令、自定义指令及自定义过滤器
- C# 模拟键盘输入
- Banner加refershscrollview
- gulp的使用
- angular自定义指令
- angular中内置的九种过滤器
- angularjs服务
- python计算一段字符串字母的和(a,b分别为1,2)
- 交换机常用命令——查看修改系统时间,查看交换机SN
- angularjs路由
- 简单了解ES6的语法
- vue计算属性computed和methods的区别
- 解决eclipse的 Invalid project description. overlaps the location of another project: 问题