流星角 - 推错误

时间:2015-11-30 03:31:12

标签: angularjs mongodb meteor

我正在使用meteor-angular,我得到了这个控制台错误:Uncaught TypeError: Cannot read property 'push' of undefined我似乎找不到任何关于如何解决此问题的文档。有谁知道如何解决这个推送错误的根源?

HTML

  <form>

    <label>Email</label>
    <input ng-model="newResonance.email">

    <button ng-click="resonance.push(newResonance); newResonance='';">Add</button>
  </form>

ClientControllerJS

(function () {
  'use strict';

  angular.module('resonance').controller('HomeCtrl', HomeCtrl);

  HomeCtrl.$inject = ['$scope', '$meteor'];

  function HomeCtrl($scope, $meteor) {

    $scope.resonance = $meteor.collection(Resonance);

    $scope.remove = function(resonance){
      $scope.resonance.remove(resonance);
    };

    $scope.removeAll = function() {
      $scope.resonance.remove();
    };

  };

})();

ServerJS

Meteor.startup(function () {

  Resonance.before.insert(function(userId, doc){

      doc.createdAt = new Date();

    });

  if (Resonance.find().count() === 0) {

    for (var i = 0; i < resonance.length; i++)

      Resonance.insert({ email: resonance[i].email });

  }
});

1 个答案:

答案 0 :(得分:0)

我通过更改来解决这个问题 <button ng-click="resonance.push(newResonance); newResonance='';">Add</button>

<button ng-click="resonance.save(newResonance); newResonance='';">Add</button>