Bads
Bads

Reputation: 774

Meteor Iron Router Wait for template to be rendered

Is there anyway to wait for template to be rendered and then execute certain function?

I have tried after and it doesn't work.

Router.map(function () {
  this.route('post', {
    path: '/posts/:ll',

    action: function () {
      this.render('home');
    },

    after: function () {
      var n = this.params.ll
       UI.insert(UI.render(Template[n]), document.getElementById("child"))
    }
  });
});

Turns out the child element doesn't exist yet because the 'home' template isn't yet rendered when the after function is fired.

Any suggestion or work around is highly appreciated.

Upvotes: 4

Views: 1998

Answers (2)

Loren
Loren

Reputation: 14836

Use onAfterAction instead of after

https://github.com/EventedMind/iron-router/blob/master/DOCS.md#before-and-after-hooks

Upvotes: 0

sbking
sbking

Reputation: 7680

Can you do this:

action: function () {
  this.render('home');
  Template.home.rendered = function() {
    // ...
    Template.home.rendered = null;
  };
},

Upvotes: 7

Related Questions