Angular Meteor 1.3 - Collection Helpers

168 Views Asked by At

I'm trying to get the most excellent dburles/meteor-collection-helpers package working with Angular Meteor 1.3. I have two collections.

    Lists.attachSchema(new SimpleSchema({
  title: {
    type: String
  },
  archived: {
    type: Boolean
  }
  createdAt: {
    type: Date,
    denyUpdate: true
  },
  sort: {
    type: Number,
    decimal: true,
    optional: true
  },
  updatedAt: {
    type: Date,
    denyInsert: true,
    optional: true
  }
}));

and cards:

Cards.attachSchema(new SimpleSchema({
  title: {
    type: String
  },
  archived: {
    type: Boolean
  },
  listId: {
    type: String
  },
  members: {
    type: [String],
    optional: true
  },
  userId: {
    type: String
  },
  sort: {
    type: Number,
    decimal: true
  }
}));

I defined a collection helper as the following:

Lists.helpers({
  cards() {
    return Cards.find({
      listId: this._id,
      archived: false
    }, {sort: ['sort']});
  }
});

I'm using publish composite to get first the list, then cards associate via a subscription. That's working hunky dory. But in my template when I can't seem to figure out to get the equivalent of list.cards() working in my ng-repeat. Here's a snip from my controller, and the relevant template markup.

$reactive(this).attach($scope);

      //note this is composite publish
      this.subscribe('list', () => {
        return [$stateParams.listId];
      });

      this.helpers({
        lists: () => {
          return Lists.findOne({_id: $stateParams.listId});
        }
      });

<a class="" ng-repeat="card in list.cards">
  • I get the infinite digest problem mostly
  • You can't call list.cards() in ng-repeat, ng-repeat doesn't work with functions, I get the infinite digest problem when I try
  • Calling as in example does nothing, but I believe that's because it returns a function.
  • Other older solutions involve just adding a scope function and querying, but that seems to not work and lose reactivity.

Anything obvious? I've seen some others having problems with this same thing but in earlier versions of angular meteor with no success, hoping someone has figured this out. Thanks.

0

There are 0 best solutions below