Hi I have nested directives where I have a parent directive along with its child directives which can be transcluded. My problem is when try to find some dom elements in the parent link function it doesn't return an array unless I set a timeout. It appears the child rendering/transclusion isn't happening fast enough. So is there a way to solve this without using a timeout and then calling find the child elements?
var app = angular.module('plunker', [])
.run(function($templateCache){
$templateCache.put('innerPane.html', "");
$templateCache.put('slidePaneSelector.html', " ");
})
.directive('innerPane', function(){
return {
restrict: 'EA',
transclude: true,
replace: true,
templateUrl: 'innerPane.html',
scope:{},
link: function(scope,element,attr){
}
}
})
.directive('slidePaneSelector', ['$timeout',function($timeout){
return {
restrict: 'EA',
transclude: true,
replace: true,
templateUrl: 'slidePaneSelector.html',
scope:{},
link: function(scope,element,attr){
var firstPaneElement = angular.element(element.find('div')[0]);
var secondPaneElement = angular.element(element.find('div')[1]);
console.log(element.find('div'));
$timeout(function(){
console.log(element.find('div'));
},100);
}
}
}]);
AngularJS Plunker
Hello {{name}}!
No comments:
Post a Comment