0

I am new to meteor. I just created a Hello world project using meteor. My project structure is very simple at the moment.

  • root folder
    • abc.css
    • abc.html
    • abc.js

In abc.js I just tried declaring a variable like this:

var lists = new Meteor.Collection("Lists");

if (Meteor.isClient) {
  Template.hello.greeting = function () {
  return "My List.";
  };

  Template.hello.events({
   'click input' : function () {
   if (typeof console !== 'undefined')
      console.log("You pressed the button");
   }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
  });
}

But when i run this, I am getting the following error in browser console:

[18:17:32.895] ReferenceError: lists is not defined

I am not sure what am I doing wrong.

1 Answer 1

3

In Meteor variables are scoped to a file. So if you define lists with the var keyword you can't access lists outside abc.js

To get passed this just remove the var so its just:

lists = new Meteor.Collection("Lists");

Then you can access it in the other files as well as your console.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.