angular-meteor根据params找到MongoDb集合并返回

Mat*_*ake 7 mongodb angularjs meteor angular-meteor

我试图通过使用Meteor和Angular.js的组合来获取MongoDb中某个地址的警告

在我的html文件中,我正在做

<div ng-controller = "myController as myCtrl">
{{myCtrl.warnings}}
{{myCtrl.getWarnings("123 Test Street, TestCity, TestState")}}
</div>
Run Code Online (Sandbox Code Playgroud)

在我的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();
    }
  }]);
}
Run Code Online (Sandbox Code Playgroud)

我的mongoDb集合:

{
    "_id": "3ixgxEMZDWGtugxA7",
    "address": "123 Test Street, TestCity, TestState",
    "warning": "Warning 1"
}
{
   "_id": "HZH5FvCD5driBYSJz",
    "address": "123 Test Street, TestCity, TestState",
    "warning": "Warning 2"
}
Run Code Online (Sandbox Code Playgroud)

html网页的输出显示整个警告集合(感谢{{currentDispatch.warnings}},但没有显示任何内容{{currentDispatch.getWarnings("123 Test Street, TestCity, TestState")}}

tma*_*ini 6

您应该使用$ 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
}
Run Code Online (Sandbox Code Playgroud)