I am working on a directive but I don't want to play with $document
or $window
, only with the element
itself.
Before I had:
angular.element($document).ready(function() {...});
and was working, just a few minutes ago I changed, and put:
element.ready(function() {...});
and it is working also.
So, when I say element.ready(function() {...})
am I telling Angular to run that function when the element <my-directive></my-directive>
is ready? or what am I doing?
I am asking this because I am wondering, why it is still working if I do element.ready
instead.
You don't need either.
ready
isn't needed since element has to exist for link function to fire. Also there is no element level ready event ... it is only used at document level to account for full body of page existing. That stage is long over when angular is compiling directives.
You can do any manipulation or event binding directly to element
immediately within link
function of directive
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With