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打開。爲什麼不是遊標?
耶穌基督!爲什麼人們需要流星的角度? – ZuzEL
看起來很合理。很多人喜歡Angular。 – stubailo