//...
compile: function(tEle,tAttrs,transcludeFn){
var tplEl = angular.element('<div>' +'<h2></h2>'+'</div>');
var h2 = tplEl.find('h2');
h2.attr('type',tAttrs.type);
h2.attr('ng-model',tAttrs.ngModel);
h2.val('hello');
tEle.replaceWith(tplEl);
return function(scope, ele, attrs){
//连接函数
};
}
//...
//下面2种定义指令的放松在功能上是完全一样的
angular.module('myApp',[])
.directive('myDirective', function (){
return {
pre: function (tElement, tAttrs, transclude){
//在子元素被链接之前执行,之后调用‘link'函数无法定位链接的元素
},
post: function (scope, iElement, iAttrs, controllers){
//在子元素被链接之后执行
}
}
});
angular.module('myApp',[])
.directive('myDirective', function (){
return {
link: function (scope, ele, attrs){
return {
pre: function (tElement, tAttrs, transclude){
//在子元素被链接之前执行,之后调用‘link'函数无法定位链接的元素
},
post: function (scope, iElement, iAttrs, controllers){
//在子元素被链接之后执行
}
}
}
}
});
//链接函数签名
link: function(scope, element, attrs){
//操作DOM
}
//含require选项, require someContainer
link: function(scope, element, attrs, someContainer){
//在这里操作DOM,可以访问require指定的控制器
}
//html
<menu-bar>
`````
<div ng-repeat="ml in menuLists">
``````
<div ng-repeat="mls in ml.secondLists">
``````
<div ng-repeat="mlt in mls.thirdLists">
``````
</div>
``````
</div>
``````
</div>
``````
</menu-bar>
//directive
angular.module('',[]).directive('menuBar',function (){
return {
restrict: 'E',
replace: true,
link: function (scope, element, attr){
//操作菜单的逻辑代码
}
}
});
//html
<div ng-repeat="ml in menuLists">
``````
<div ng-repeat="mls in ml.secondLists">
``````
<menu-bar>
``````
<div ng-repeat="mlt in mls.thirdLists">
``````
<menu-bar>
``````
</menu-bar>
``````
</div>
``````
</menu-bar>
``````
</div>
``````
</div>
//directive
angular.module('',[]).directive('menuBar',function (){
return {
restrict: 'E',
replace: true,
link: function (scope, element, attr){
//操作菜单的逻辑代码
}
}
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有