As of recently all documentation of meteor states that onRendered
is a new way to get a callback when template has finished rendering. and rendered
is just for backwards compatibility.
However, that just does not seem to work for me. onRendered
never gets executed, while rendered
does. I have newest meteor version 1.1.0.2
//only this is executed
Template.hello.rendered = function(){
console.log('rendered');
}
//and this is not
Template.hello.onRendered = function(){
console.log('onRendered');
}
//even if I comment first one out
and both functions in action you can see in this github repo. Am I doing something wrong, or this is a defect in onRendered?
and second question - reason why I started to dig into this - how can I execute code every time an dom element is added/removed to my template? rendered
does not seem to get called when that happens. Is there any other way?
onRendered takes a function as an argument. Try this instead:
Template.hello.onRendered(function() {
console.log('onRendered');
});
With that change, you should find both rendered
and onRendered
will be called. Also note that you can now add multiple onRendered
callbacks for a given template.
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