Tuesday 30 April 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...