如何在angular指令渲染模板完毕后再执行link方法,render完毕再在link中操作dom节点
2015-11-15 11:41
671 查看
解决办法很简单,在link方法中,使用
$timeout(function(){
……
});
examplemyModule.directive('myTab',['$timeout',function($timeout){
return {
restrict:'E',
repalace:true,
templateUrl:'19tpl.html',
scope:{
myId:'@',
myData:'='
},
controller:['$scope',function($scope){
$scope.name="ctrl共享的数据";
}],
link:function(scope,element,attr,reController){
//在这里用jq操作dom
// console.log(scope.name)
// console.log(element)
// console.log(attr)
$timeout(function(){
console.log(element.find('li').length);
element.find('li').on('click',function(){
alert(1)
})
},0);
}
};
}]);
$timeout(function(){
……
});
examplemyModule.directive('myTab',['$timeout',function($timeout){
return {
restrict:'E',
repalace:true,
templateUrl:'19tpl.html',
scope:{
myId:'@',
myData:'='
},
controller:['$scope',function($scope){
$scope.name="ctrl共享的数据";
}],
link:function(scope,element,attr,reController){
//在这里用jq操作dom
// console.log(scope.name)
// console.log(element)
// console.log(attr)
$timeout(function(){
console.log(element.find('li').length);
element.find('li').on('click',function(){
alert(1)
})
},0);
}
};
}]);
相关文章推荐
- 对AngularJS中无法直接获取Promise状态的不解
- [AngularJS] Use ng-model-options to limit $digest
- AngularJS指令参数详解
- AngularJs ngInclude、ngTransclude
- AngularJs ngIf、ngSwitch、ngHide/ngShow
- AngularJs ngReadonly、ngSelected、ngDisabled
- 慎用angular.forEach
- Angular规范
- 购物车Demo,前端使用AngularJS,后端使用ASP.NET Web API(3)--Idetity,OWIN前后端验证
- 购物车Demo,前端使用AngularJS,后端使用ASP.NET Web API(2)--前端,以及前后端Session
- 购物车Demo,前端使用AngularJS,后端使用ASP.NET Web API(1)--后端
- AngularJs ngList、ngRepeat、ngModelOptions
- angularjs学习大纲
- angularjs中service、factory和provider的区别
- angularjs 的controller的三种写法
- AngularJS:何时应该使用Directive、Controller、Service?
- AngularJS的学习--$on、$emit和$broadcast的使用
- window.location方法获取URL及window.location.assign(url)和replace(url)区别
- AngularJS模块加载
- window.location.hash属性介绍