Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor.js onRendered & rendered

Tags:

meteor

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?

like image 765
Martins Untals Avatar asked Apr 27 '15 18:04

Martins Untals


1 Answers

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.

like image 172
David Weldon Avatar answered Nov 01 '22 03:11

David Weldon