function link(scope, iElement, iAttrs, controller) { ... }
Can anyone give an example to explain where exactly attr refers to in the angular instruction?
How to obtain the data in attrs.data below, or where to set it? How to write
in <demo></demo>app.directive('demo',function(){
return{
template: '<p></p>',
link : function(scope, element, attrs){
if($.trim(attrs.data).length>0){
}
},
}
}
)
html:
<demo></demo>
The execution time of the link function is after angular compiles this template. 4 parameters:
scope The scope of the current directive, whether it is independently determined by the scope parameter
element The dom element of the current directive is wrapped with angular.element(element) to form a jqlite/jquery object
Attributes corresponding to the attrs directive. For example
The attrs.data is 'some data' which is hard-coded. If you want to bind it, it must be scoped independently.
controller is the method provided by the required directive. If multiple are required, controller will be an array.