Meteor: data passed to template from Iron Router, is empty at first load -


i'm facing strange problem. i'm using iron router controller pass data template:

router.route('/wards/add/:_id?', {name: 'wards.add', controller: 'wardaddcontroller'});      wardaddcontroller = routecontroller.extend({       action: function() {         this.render('addward', {            data: function(){             return { hospitals : hospitals.find({}), hospital_id : this.params._id }           }         });       }     }); 

i return variable 'hospitals', should contain collection data. template:

<div class="jumbotron">     {{#each hospitals}}         {{name}}<br>     {{/each}} </div> 

at first page load, if type directly url of page, there no items. if type hospitals.find({}).fetch() (insecure active) in browser console, return empty object.

but if change pages, navigating on website while, , return the listing page, items appears.

any idea?

in server folder, add publish.js , inside add:

meteor.publish('hospitals', function() {   return hospitals.find({}); }); 

then try subscribing hospitals controller:

wardaddcontroller = routecontroller.extend({   action: function() {     this.render('addward', {        waiton: function() {         return [               meteor.subscribe('hospitals')            ];       },       data: function(){         return { hospitals : hospitals.find({}), hospital_id : this.params._id }       }     });   } }); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -