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