Hello, I learned meteor through the University of London specializations courses. It was with an older version, not using imports. I know that there is a great value to the import statements but I wanted to try and see if the tutorial works without it.
I have the following html:
<body>
<div class="container">
<header>
<h1>Todo List</h1>
<form class="new-task">
<input type="text" name="text" placeholder="Type to add new tasks" />
</form>
</header>
<ul>
{{#each tasks}} {{> task}} {{/each}}
</ul>
</div>
</body>
<template name="task">
<li>{{text}}</li>
</template>
Then in the server folder (main.js)
var Tasks = new Mongo.Collection('tasks');
and finally in the client folder (main.js)
Template.body.helpers({
tasks() {
return Tasks.find({});
},
});
Template.body.events({
'submit .new-task' (event) {
// Prevent default browser form submit
event.preventDefault();
// Get value from form element
const target = event.target;
const text = target.text.value;
// Insert a task into the collection
Tasks.insert({
text,
createdAt: new Date(), // current time
});
// Clear form
target.text.value = '';
},
});
However, when I run this. I get the error that Tasks is not defined.
Why am I getting this error, shouldn’t it communiciate with the server.js file and know that Tasks has been defined as a database? Even if I put in an import statement (which I am currently trying to avoid just to see if it can be done) it doesn’t work.
How can I fix this?