Mongo.Cursor ngFor


#1

I’m very new to Meteor, and i’m trying to do a simple test with Mongo (similar to the tutorial) as follows:

(part of my Angular 2 Component)

export class JobsComponent {
  jobs: Mongo.Cursor<Object>;

  constructor() {
    this.jobs = Jobs.find();
  }
}

Then i’m trying to iterate over ‘jobs’ using:
*ngFor="let job of jobs"

But I get an error saying:

Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.

How do I convert the Mongo.Cursor object into an iterable array?

Thanks


#2

Sorry I managed to get it working with pub/sub method explained here:

https://www.angular-meteor.com/tutorials/socially/angular2/privacy-and-publish-subscribe-functions

(I don’t know how to remove this topic…)


#3

Don’t worry about removing it - leaving questions like this here, with a solution, will more than likely help someone else down the road.


#4

But the question remains. I have same issue, when I do exactly like in tutorial it works, in my case it’s not. I have checked in both cases it receives a Cursor.
I dig further, but maybe there is a quick answer from guru?:slight_smile:


#5

Ok, I found the problem. RTFM!)

import {bootstrap} from ‘angular2-meteor-auto-bootstrap’;
And now you can iterate Mongo.Cursor objects with Angular 2.0 ngFor!


#6

angular2-meteor is a fast moving target. A lot has been done to make it as simple to use as blaze was. I think recently @Urigo added component MeteorReactive and some service providers METEOR_PROVIDERS that helps make ngFor work smoothly with Mongo Cursors.

Check the below links to know more:

https://www.npmjs.com/package/angular2-meteor#using-angular-2-in-a-meteor-app

Also check this example repo to know, how METEOR_PROVIDERS are injected into app module and how MeteorReactive to extend to define components with reactive attributes. Both of these do the magic of making ngFor work with Mongo Cursors.


#7

thanks @gauravdhiman

Yes it was a fast moving target, but not anymore.
The API is solid and everyone can start using it