12

After working fine with

Template.name.rendered = function () { ..... }

I changed this to:

Template.name.onRendered(function(){ ..... })

but I don't have the same results and I don't find too much documentation about the differences, some one would help me please? or someone knows where I can see the differences?

Zilev av
  • 491
  • 1
  • 7
  • 21
  • Can you describe a little bit more what kind of different behavior your are experiencing? – Tomasz Lenarcik Apr 22 '15 at 22:03
  • It is like in onRendered the data doesn't arrive as soon as in rendered does, I have to refresh to have the correct data, but maybe I'm using in a wrong way (because the api changed), I would like to see the differences in some place, but I don't find too much documentation about that :( – Zilev av Apr 22 '15 at 22:16
  • 1
    There's no difference between `rendered` and `onRendered`, it's supposed to be the exact same API. – saimeunt Apr 22 '15 at 22:23
  • They should be equivalent and produce the same results. Can you post your code inside the rendered function? – Jeremy S. Apr 22 '15 at 22:23
  • Template.myTemplate.onRendered(function(){ this.autorun( ) { Template.currentData(); ..............show that data............. } }) – Zilev av Apr 22 '15 at 22:24
  • 1
    rendered is getting deprecated. use `Template.home.onRendered(// function)` – Mustafa Apr 23 '15 at 01:54
  • 1
    @zilevav Looking at the implementation [here](https://github.com/meteor/meteor/blob/devel/packages/blaze/template.js#L203) there's no way there's a difference between those two "uses" unless you're comparing it with the behavior on some older version of Meteor. – Tomasz Lenarcik Apr 27 '15 at 15:46

1 Answers1

17

In Meteor 1.0.4 rendered got deprecated and replaced by onRendered:

Add onRendered, onCreated, and onDestroyed methods to Template. Assignments to Template.foo.rendered and so forth are deprecated but are still supported for backwards compatibility. Source: History.md

If you see "wrong" behavior when using onRendered please make sure you are using Meteor 1.0.4 or newer.

Stephan
  • 1,279
  • 8
  • 16
  • I am using Meteor 1.2.1 and the onRendered simply does not fire, while rendered does :( – Predrag Stojadinović Dec 24 '15 at 15:04
  • 3
    Hi @PredragStojadinović, I have found the same issue. With onRendered it was simply not working. I am using a sequence of collection.find calls and updating the DOM with jquery. With rendered it was working beautifully. I then found my mistake... I had chnaged to Template.name.onRendered = function () { ..... } , only changing rendered for onRendered, instead of using it as a callback like Template.name.onRendered(function(){ ..... }) . Not using "=". After correcting it, it started working fine. – Juliomac Jun 22 '16 at 18:47