I am a bit confused about my code not working as I expected.
I am just initializing a reactive-var in my template onCreated method, and trying to read it in a helper. But I got undefined from the reactive-var.
Here is the code :
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import './record-infos-page.html';
import './record-infos-page.scss';
Template.Record_infos_page.onCreated(function recordInfosPageOnCreated() {
this.checkedVariablesIds = new ReactiveVar(['HkcEjZjdxbobbNCZc', 'uTmJKTfoWFFfXPMwx']);
console.log(1, this.checkedVariablesIds.get());
});
Template.Record_infos_page.helpers({
checkedVariablesIds() {
const checkedVariablesIds = Template.instance().checkedVariablesIds.get();
console.log(2, checkedVariablesIds);
return checkedVariablesIds;
},
});
And here is the console.log result:
1 ["HkcEjZjdxbobbNCZc", "uTmJKTfoWFFfXPMwx"]
2 undefined
So my reactive var is well initialized, but is not passed to the helper. Why?