[英]How to pull items from a collection using meteor?
I'm new to meteor and I'm trying to run the very beginners tutorial and I'm having troubles reading data from a collection. 我是流星的新手,正在尝试运行初学者教程,但是从集合中读取数据时遇到了麻烦。
Here's my js 这是我的js
import angular from 'angular';
import angularMeteor from 'angular-meteor';
import { Tasks } from '../../api/tasks.js';
import template from './todosList.html';
class TodosListCtrl {
constructor($scope) {
$scope.viewModel(this);
this.helpers({
tasks() {
return Tasks.find();
}
})
}
}
export default angular.module('todosList', [
angularMeteor
])
.component('todosList', {
templateUrl: 'imports/components/todosList/todosList.html',
controller: TodosListCtrl
});
and I have declared my collection like this (imports/api/tasks.js): 并且我已经这样声明了我的收藏集(imports / api / tasks.js):
import { Mongo } from 'meteor/mongo';
export const Tasks = new Mongo.Collection('tasks');
I'm sure I'm missing something simple, will accept any help. 我确定我缺少简单的东西,会接受任何帮助。
you need to be able to access the scope. 您需要能够访问范围。 in your component, you shoud have
controller: ['$scope', TodosListCtrl]
在组件中,应该有
controller: ['$scope', TodosListCtrl]
Then if you insert a new task, you will see it db.tasks.insert({ text: "Hello world!", createdAt: new Date() });
然后,如果您插入一个新任务,您将看到它
db.tasks.insert({ text: "Hello world!", createdAt: new Date() });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.