Sorry, ES6 newb here:
Template.hello.onCreated( () => {
// counter starts at 0
this.counter = new ReactiveVar(0);
});
Template.hello.helpers({
counter() {
return Template.instance().counter.get();
},
});
Template.hello.events({
'click button'(event, instance) {
// increment the counter when button is clicked
instance.counter.set(instance.counter.get() + 1);
},
});
When I click on the button I get Cannot read property 'get' of undefined
But when I do
Template.hello.onCreated( function(){
// counter starts at 0
this.counter = new ReactiveVar(0);
});
it works fine.
So there's something going on with ES6's fat arrow binding of the this
keyword that I'm not getting?