解决办法很简单,在link方法中,使用
$timeout(function(){
……
$timeout(function(){
……
});
example
myModule.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);
}
};
}]);