2015-07-19 54 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函數是一個有趣的想法。 是否想要使用該函數來返回過濾對象? 你可以使用過濾器,但也許我們可以添加此選項以及