Derek
Derek

Reputation: 695

Subscribe with parameters with Meteor-Angular

I am new to Meteor and I am trying to build an online reporting app with angular-meteor but I am having problems trying to publish and subscribe with parameter(s).

In lib/collections.js,

TestReport = new Mongo.Collection('test_report');

In server/publications.js,

Meteor.publish('testReportDetail', function(reportID) {
    check(reportID, String);

    return TestReport.findOne({_id: reportID});
});

In client/test_report_detail.js,

angular.module('myapp').controller('myCtrl', function($scope, $reactive, $stateParams) {
    $reactive(this).attach($scope);

    this.subscribe('testReportDetail', $stateParams.reportID);

    this.helpers({
        reportDetail: function() {
            return TestReport.find({_id: $stateParams.reportID});
        }
    });
});

When client browser tries to access report detail it gets the error in console

typeError: fn is not a function

Any idea...?

Upvotes: 0

Views: 455

Answers (2)

Urigo
Urigo

Reputation: 3185

There was a fix for this.subscribe in the new 1.3.1 release I've just published, please check again - https://github.com/Urigo/angular-meteor/releases

Upvotes: 1

Eugenious
Eugenious

Reputation: 36

In server/publications.js you should be using find() instead of findOne().

Meteor.publish('testReportDetail', function(reportID) {
    check(reportID, String);

    return TestReport.find({_id: reportID});
});

Although the signatures of those two functions are similar, they return very different things! find() will return a cursor, but findOne() actually returns an object.

Here's the relevant documentation for Meteor.publish().

Also see documentation for Collections.find()

Upvotes: 0

Related Questions