【问题标题】:angular-meteor "Cannot read property 'find' of undefined"角流星“无法读取未定义的属性‘查找’”
【发布时间】:2016-05-19 08:20:35
【问题描述】:

我在 cloud9 IDE 下运行这个应用程序。流星1.3.2.4

流星列表:

角度 1.3.10
自动发布 1.0.7
es5-shim 4.5.10
不安全的 1.0.7
jQuery 1.11.8 流星基地 1.0.4
移动体验 1.0.4
mongo 1.1.7
反应变量 1.0.9
标准-minifier-css 1.0.6
跟踪器 1.0.13

我的 ./client/main.html

<head>
  <title>Joakenpo</title>
</head>

<body ng-app="joakenpo">
  <h1>Joakenpo</h1>
  <div ng-controller="MainCtrl">
    <ul>
      <li ng-repeat="person in list">{{person.name}}</li>
    </ul>
  </div>
</body>

我的 ./server/main.js

List = new Mongo.Collection('list');

Meteor.startup(() => {
    console.log('Joakenpo running');
    ['John', 'Peter', 'Rachel'].map((name) => List.insert({ name: name }));
    console.log(List.find().count());
});

我的 ./client/main.js

angular
  .module('joakenpo', ['angular-meteor'])
  .controller('MainCtrl', ($log, $scope) => {
    $log.debug('main controller');
    $scope.message = 'Module running';
    $scope.helpers({
      list() {
        return Meteor.List.find({});
      }
    });
  })
  .run(($log) => $log.debug('Joakenpo Module Running'));

我的错误

angular_angular.js?hash=c17a5a9…:12535 TypeError: Cannot read property 'find' of undefined

【问题讨论】:

标签: angularjs mongodb meteor collections angular-meteor


【解决方案1】:

您需要在通用代码中定义您的 List 集合,而不仅仅是在 server.js 中。另外你不能把它称为Meteor.List,你还需要导入它。

本教程展示了如何正确地完成所有这些操作:https://www.meteor.com/tutorials/angular/collections

【讨论】:

  • 好了,终于成功了!我创建了一个新文件夹 ./lib,在其中保存了一个 main.js 文件,其中只有一行 "List = new Mongo.Collection ('list');"!在客户端 main.js 中,我将 $scope.helpers 切换为 "$scope.list = $meteor.collection (List)"非常感谢您
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-21
  • 1970-01-01
  • 2020-10-04
  • 2018-12-29
  • 2015-07-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多