Last Updated: February 25, 2016
·
5.887K
· yozawiratama

waitOn and Multiple subscriptions in iron-router

Hi, this time i want to share how to do multiple subscription in iron-router. as we know iron-router has waitOn as great feature, we can wait subscription finsih before rendering template or page. this is how to the simple way to use waitOn :

this.route('posts', {
    path: '/posts',
    template: 'tmp_posts',
    waitOn: function () {
        return Meteor.subscribe('posts');
    },
    onBeforeAction: function () {
    },
    onAfterAction: function () {

    },
    data: {

    }
});

and this is how to subscribe more than one subscription

this.route('posts', {
    path: '/posts',
    template: 'tmp_posts',
    waitOn: function () {
        return [Meteor.subscribe('posts'),Meteor.subscribe('users')];
    },
    onBeforeAction: function () {
    },
    onAfterAction: function () {

    },
    data: {

    }
});

Hope this help you.

3 Responses
Add your response

could you please show how to waiton other things? As a simple example: waiton a Meteor.setTimeout

over 1 year ago ·

Thanks for this

over 1 year ago ·

Thanks pal!

over 1 year ago ·