我正在尝试使用Meteor和Angular.js的组合在我的MongoDb中获取某个地址的警告
在我的html文件中,我正在做
<div ng-controller = "myController as myCtrl">
{{myCtrl.warnings}}
{{myCtrl.getWarnings("123 Test Street, TestCity, TestState")}}
</div>在app.js文件中:
Warnings = new Mongo.Collection("Warnings");
if (Meteor.isClient) {
var app = angular.module('ffprototype', [ 'angular-meteor' ]);
app.controller('myController', ['$window','$meteor', function($window, $meteor) {
this.warnings = $meteor.collection(Warnings);
this.getWarnings = function(findByAddress){
Warnings.find({address: findByAddress}).fetch();
}
}]);
}我的mongoDb收藏:
{
"_id": "3ixgxEMZDWGtugxA7",
"address": "123 Test Street, TestCity, TestState",
"warning": "Warning 1"
}
{
"_id": "HZH5FvCD5driBYSJz",
"address": "123 Test Street, TestCity, TestState",
"warning": "Warning 2"
}html网页的输出显示了整个Warnings集合(感谢{{currentDispatch.warnings}},但{{currentDispatch.getWarnings("123 Test Street, TestCity, TestState")}}没有显示任何内容
发布于 2015-05-12 03:35:56
为此,您应该使用$meteor.object
this.getWarnings = function(findByAddress){
$meteor.object(Warnings, { address: findByAddress }, false); // passing false here to not update the collection from changes in the client
}发布于 2016-03-19 23:33:53
从angular-meteor docs来看,$meteor.object似乎很快就会被弃用。
不再需要$meteor.object,因为我们可以使用Mongo Collection的findOne函数,如下所示。
旧代码:
$scope.party = $meteor.object(Parties, $stateParams.partyId);新代码:
$scope.helpers({
party() {
return Parties.findOne($stateParams.partyId);
}
});更详细的bind one tutorial。
https://stackoverflow.com/questions/30140736
复制相似问题