我想获得在我的MongoDB中的某个地址的警告,使用流星和Angular.js角流星发现MongoDB的收集和返回基于PARAMS
在我的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网页的输出显示了整个警告集合(感谢{{currentDispatch.warnings}}
,但没有得到显示{{currentDispatch.getWarnings("123 Test Street, TestCity, TestState")}}
如果我这样做,我不会放松自动发布功能吗? 'this.warnings = $ meteor.collection(Warnings);'自动将更新推送到数据库,但是当我必须“返回”时,那些东西不会丢失? –
你是对的,看我的编辑 – tmaximini
谢谢我回家后试试看,如果这个工程我会接受,你会得到你的要点 –