微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angularjs – angular-meteor基于params找到MongoDb集合和返回

我试图通过使用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,TestState","warning": "Warning 1"
}
{
   "_id": "HZH5FvCD5driBYSJz","warning": "Warning 2"
}

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

你应该使用 $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
}

原文地址:https://www.jb51.cc/angularjs/141236.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐