Last Updated: February 25, 2016
·
6.177K
· 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 ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside