I've been reading lots of question for hours on StackOverflow but still not reach the solution.
I have to add class="active"
to a sibling element after DOM has finished rendering. I wrote a directive to do that and put in it $timeout()
with 0 delay but it doesn't work.
Here's the code:
angular.module('test', [])
.directive('updateTextField', function(){
return{
link: function(scope, element, attr){
$timeout(function(){
var label = element.siblings('label');
label.addClass('active');
console.log(label); //for debugging purposes
}, 0);
}
}
})
The result of console.log('label')
is an element with the class active
but if I inspect it directly, it hasn't class active.
Any help would be appreciated