1

I am using Meteor,so can someone suggest me what could be the event which can be handled after a Template is displayed(not loaded)...? For example , I have a template which displays a modal popup. Now I want to do something after the template is "displayed" (not loaded). Please suggest me how to handle the respective event. I have tried,

<template name = "SendMessage">

//modal popup code
{{check}}
</template> 

Template.SendMessage.check = function(){
alert("load");
};
The lost Dev
  • 105
  • 2
  • 10
  • Please take a look at http://stackoverflow.com/questions/10109788/callback-after-the-dom-was-updated-in-meteor-js. Is it working for you? – jifeng.yin Aug 09 '12 at 02:21

3 Answers3

1

For Meteor starting from 0.4.0 preview, you might want to use Template.myTemplate.rendered and use a boolean value to track the state within the Template object like this (so it does not get called every time a portion of the template is updated):

Template.myTemplate.rendered = function() {
    if(!this._rendered) {
      this._rendered = true;
      alert('load');
    }
}
Joscha
  • 4,643
  • 1
  • 27
  • 34
0

You can achive that in this hacky way:

Template.SendMessage.check = function(){
   Meteor.defer(function(){ 
         //modal code
   });
};

Or more hacky

Template.SendMessage.check = function(){
  setTimeout(function(){    
         //modal code
   },0);
};
Topicus
  • 1,394
  • 1
  • 15
  • 27
0

Say you have one template which renders once but want to react when the url changes, like load different modals and such. If that is the case this a possible way.

Template.PageDetail.onRendered(function(){
    this.autorun(() => { 
        FlowRouter.watchPathChange();
        // do the thing!
        yourFunction();
    })
})
2046
  • 331
  • 3
  • 3