angularjs directive link 属性 问题
来源:互联网 发布:巨杉数据库 文档 编辑:程序博客网 时间:2024/05/15 23:45
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'; } };});
这个在官网上的directive代码,link函数起到的什么作用,解释有点费解,然后其中有三个参数
scope:is an Angular scope object.element: is the jqLite-wrapped element that this directive matches.attrs: is a hash object with key-value pairs of normalized attribute names and their corresponding attrib
首先我们先来聊聊你列出的directive
中的几个属性:
restrict
E: 表示该directive
仅能以element方式使用,即:<my-dialog></my-dialog>
A: 表示该directive
仅能以attribute方式使用,即:<div my-dialog></div>
EA: 表示该directive
既能以element方式使用,也能以attribute方式使用
transclude
你的directive
可能接受页面上的其他html内容时才会用到,建议你先去掉该参数。有些高阶了。
scope
当你写上该属性时,就表示这个directive
不会从它的controller
里继承$scope
对象,而是会重新创建一个。templateUrl
你的directive
里的html
内容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'
}
0 0
- angularjs directive link 属性 问题
- AngularJs directive-link实例
- angularjs directive内部controller link函数理解
- AngularJs 指令directive之controller,link,compile
- AngularJs 指令directive之controller,link,compile
- AngularJs 指令directive之controller,link,compile
- angularJS directive自定义标签和属性
- AngularJS自定义指令directive:scope属性
- AngularJS自定义指令directive:scope属性
- AngularJS自定义指令directive:scope属性
- angularJS directive中的controller和link function辨析
- AngularJS--directive
- angularjs directive
- AngularJS: directive
- angularJs中指令的directive的controller属性
- angularJS 自定义指令 方法属性:compile、link
- AngularJS的指令(Directive) compile和link的区别及使用示例
- angularjs directive 获取scope内容不正确的问题。
- Android中最常用的适配器:PagerAdapter与FragmentPagerAdapter
- hdu 5920 Ugly Problem(CCPC长春,构造回文数)
- Android Studio 注释模板
- 驱动开发入门——NTModel
- TP-LINK NVR与IPC的使用方法
- angularjs directive link 属性 问题
- Gson使用及多层嵌套 json 定义类
- 52.[Python]使用threading进行多线程编程
- 使用ReactiveCocoa实现iOS平台响应式编程
- 单例模式——国庆收心
- 智慧北京:XUtils的View的注入
- 快速排序
- 如何使用VMware Workstation 12 安装Ubuntu虚拟机
- JSON