David Gomes
David Gomes

Reputation: 5845

Session.set vs changing the variable

I have this template:

<body>
  {{> hello}}
</body>

<template name="hello">
  {{greeting}}
</template>

And this is the controller:

if (Meteor.isClient) {
  Template.hello.greeting = "Hi";

  Meteor.setInterval(function() {
    Session.set("greeting", Values.findOne({}).value.toString());
    console.log(Values.findOne({}).value);
  }, 1000);

}

On the console I'm getting the value in the collection Values. However, when I Session.set it to greeting, the variable isn't updated on the HTML page. The "Hi" I default it to just stays there while every second I get the value that should be in it on the console.

Upvotes: 0

Views: 99

Answers (1)

Tomasz Lenarcik
Tomasz Lenarcik

Reputation: 4890

Try doing this:

Template.hello.greeting = function () {
  return Session.get('greeting');
});

Upvotes: 4

Related Questions