Update template var

I’m trying to update a reactive var in my template with a value returned from a method on the server. I can see that the server is returning a value but I cant set the var myvar1 in the code below. What am I doing wrong? Thanks for any help.

        Meteor.call('mymethod', arg1, function(err, ret) {
        // Also tried this and self

in what function/helper or so you are calling that?

In Template.mytpl.events

Template.mytpl.created = function() {

this.myvar1 = new ReactiveVar(false);


and if you do in that onCreated. (And BTW it is onCreated in current meteor version, not created)

self = this;

and in that callback


? there was thread regarding similar scoping inside callbacks on these forums.
But I dont remember what was the solution, I would try this one first probably.

Thanks for your answer but I have tried that and also


with no success.

Maybe this:

var instance = Template.instance();
Meteor.call('mymethod', arg1, function(err, ret) {

I did not notice that events handler.

you can pass event AND template instance as argument for event handlers.


‘click’: function(event, instance) {

mby :smiley:

YES, thats the way to do it. Thanks a lot Steve and shock.
In other situations with callbacks it usually works to do self = this and then use self in callback but not this time and with reactive var. Nice and easy solution, thanks.