2015-07-19 52 views
0

Angular-Meteor tutorial step 9后,我试图创建一个使用Meteor集合的Angular指令。

此文件是在根文件夹:

TicTacToeBoards = new Meteor.Collection("tic_tac_toe_boards"); 

if (Meteor.isServer) { 
    Meteor.publish('TicTacToeBoards', function() { return TicTacToeBoards.find(); }); 
} 

此文件在/客户端文件夹:

angular.module('TicTacToe').directive('tictactoegraph', function() { 
    return { 
     templateUrl: 'client/graph/tictactoegraph.ng.html', 
     scope: true, 
     controller: function($scope, $meteor, Sigma, TicTacToeClass) { 
      $scope.TicTacToeBoards = false; 

      $meteor.subscribe('TicTacToeBoards').then(function(subscriptionHandle){ 
       $scope.TicTacToeBoards = $meteor.collection(TicTacToeBoards); 
      }); 
     }, 
     link: function($scope, element, attrs) { 
      // TODO: Ask SO if there's a better way to wait on the subscription.... 
      $scope.$watch('TicTacToeBoards', function(newValue, oldValue) { 
       if ($scope.TicTacToeBoards) { 
        console.log($scope.TicTacToeBoards); // An array of objects. 
        var nextBoards = $scope.TicTacToeBoards.find({ numberOfMoves: 0 }); 
       } 
      }); 
     } 
    } 
} 

不幸的是,它提供了一个错误:

TypeError: $scope.TicTacToeBoards.find is not a function

它看起来$scope.TicTacToeBoards不是Mongo游标,而是TicTacToeBoards.find()将对象的数组E打开。为什么不是游标?

+0

耶稣基督!为什么人们需要流星的角度? – ZuzEL

+0

看起来很合理。很多人喜欢Angular。 – stubailo

回答

1

你说得对,$ meteor.collection不返回游标,它返回一个类型AngularMeteorCollection的数组是不同的: http://angular-meteor.com/api/AngularMeteorCollection

它确实是因为我们想给开发者角度与规则阵列它的API可以轻松使用。

尽管为该数组添加find函数是一个有趣的想法。 是否想要使用该函数来返回过滤对象? 你可以使用过滤器,但也许我们可以添加此选项以及