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?
{{#if currentUser}} <input ...> {{/if}}
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 .
Meteor.user()
, {{#if}} , onRendered , , , HTML DOM.
{{#if}}
onRendered
HTML
<template name="parentTemplate> {{#if currentUser}} {{> childTemplate}} {{/if}} </template> <template name="childTemplate"> {{! whatever}} </template>
JS
Template.childTemplate.onRendered(function(){ // here you go });
autorun.
autorun
Template.mytemplate.onRendered(function() { Tracker.autorun(function() { user = Meteor.user() if (user) { // Your code here } } }