I want to access ReactiveVar variable in onRendered getting error Exception in delivering result of invoking 'getUsersData': TypeError: Cannot read property 'userData' of null
Template.editAdmin.onCreated(function() {
this.userData = new ReactiveVar([]);
});
Template.editAdmin.onRendered(function() {
Meteor.call("getUsersData", this.data, function(err, result) {
Template.instance().editAdminId.set(result);
});
});
It doesn't look like your code sample lines up with your error message. You mentioned the error is:
TypeError: Cannot read property 'userData' of null
but from looking at your code sample, I can see the error will really be:
TypeError: Cannot read property 'editAdminId' of null
I'll assume you want it working with userData
, so I'll adjust your code accordingly. Basically you want to make sure you're leveraging javascript closure properly when using Template.instance()
in your Method callback. For example:
Template.editAdmin.onCreated(function () {
this.userData = new ReactiveVar([]);
});
Template.editAdmin.onRendered(function () {
const instance = Template.instance();
Meteor.call("getUsersData", this.data, function (err, result) {
instance.userData.set(result);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With