Tuesday, April 30, 2019

angularjs - Angular js timeout inside link function after dom manipulation

I have a directive, through which I am dynamically adding span before a label in html. The span tag is created using template property. Now I have one case where label is displayed none so no need for span to add.



Can we use timeout inside link function after DOM manipulation is completed in link function? Since i am able to get instance of all label elements after DOM has completed loading. Below is the directive code working as expected.



myModule.directive('lockIcon', ['$compile', '$filter', '$timeout', function($compile, $filter, $timeout) {
return {
restrict: 'A',
scope: {
visible: '=visible'
},

link: function (scope, element) {
var template = '';
var newElement = angular.element(template);
element.wrap( '
' ).parent().append(newElement);
$compile(newElement)(scope);
$timeout(function() {
var lockLabelElm = angular.element('.lock-icon-wrapper label');
if(lockLabelElm) {
angular.forEach(lockLabelElm, function(elmlock) {
var labelDisplayState = angular.element(elmlock).css('display');

if(labelDisplayState === 'none') {
angular.element(elmlock).next().css('display','none');
}
});
}
});
}
};
}]);

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...