Meteor reactive template update feature

I want to solve the following problem in Meteor.js:

I have an HTML element that appears in the template only if the user is logged on: {{#if currentUser}} <input ...> {{/if}}. After the HTML element appears, I need to execute the JS command on it. So I need some kind of callback that happens after updating the Template. How to achieve this?

None of the reactive data sources that I know do in this case, for example, the source Meteor.user()fires dependency triggers before updating the Template. Also see my previous question here .

+3
source share
2 answers

, {{#if}} , onRendered , , , HTML DOM.

HTML

<template name="parentTemplate>
  {{#if currentUser}}
    {{> childTemplate}}
  {{/if}}
</template>

<template name="childTemplate">
  {{! whatever}}
</template>

JS

Template.childTemplate.onRendered(function(){
  // here you go
});
+3

autorun.

Template.mytemplate.onRendered(function() {
   Tracker.autorun(function() {
     user = Meteor.user()
     if (user) {
        // Your code here
     }
   }
}
0

All Articles