[Solved] Having a template wait for subscription of parent template

I am getting an intermittent “bad index error” from a dropdown that displays items read in a collection.

The collection subscribe is in /myapp/myapp.js


The dropdown needs a javascript initialization that I do in the onRendered callback

Template.dropdown.onRendered((function () { this.$('.ui.dropdown').dropdown() })

I suspected the javascript initialization was running before all the data was synchronized so I tried two things

  • A dropdown that doesn’t need javascript initialization
  • Moving the subscribe to the dropdown template and adding a {{#if Template.subscriptionsReady}} in the template

In both cases the error disappears. But the subscription is a bit slow - that’s why it was in the root level to start with so its starts loading while the user is busy reading and deciding what page to open, one if which contains the said dropdown.

Is there a way I can get a template to wait for a subscription that is in a parent template ?

You don’t have to move the subscription, just pass subscriptionsReady to the child template and it will work.


That’s a brilliant idea !