Reputation: 1657
I try to set a ReactiveDict-variable on a custom event inside of on()
, but I get this error: Uncaught TypeError: Cannot read property 'templateDictionary' of null
.
The second question is, if it would make sense to define the ReactiveDict()
in onRendered
?
Template.something.onCreated(function() {
this.templateDictionary = new ReactiveDict();
});
Template.something.onRendered(function() {
anything.on({
'element:mouseover': function(elementView, event){
Template.instance().templateDictionary.set( 'showExtraFields', true );
}
});
});
Template.something.helpers({
anything: function() {
var result = Template.instance().templateDictionary.get( 'showExtraFields' );
console.log(result);
}
});
Upvotes: 2
Views: 94
Reputation: 27793
I have no idea what anything.on
is, but try this:
Template.something.onRendered(function() {
anything.on({
'element:mouseover': (elementView, event) => {
this.templateDictionary.set( 'showExtraFields', true );
}
});
});
Use the ES6, Luke!
Upvotes: 0
Reputation: 17
Put instance reference inside onRendered function. Not inside another function. Scope issue.
Upvotes: 2