Open crapthings opened 10 years ago
The problem here is that the first argument of the $collection service must refer to the name of the collection object, and that name also has to be the same as the publisher function name. So, you would need to have a collection called Notes and a collection called stickyNotes, which is not viable. And adding to the problem, you cannot specify which model you want the fetched array to be bound to because the $collection object will automatically bind the fetched array to $scope.Notes and $scope.stickyNotes. From this, we can see that there are obvious limitations to how the current $collection service works and I'm working on removing these limitations in v0.2 of ngMeteor.
The alternative for now is to use AngularJS filter service to filter your collection. Optionally, you can also use AngularJS orderBy to sort your collection.
Assuming the collection is in an object called Notes
, you would get all your notes using:
$collection('Notes', $scope, {creatorId: Meteor.userId()}, {sort: {createdAt: -1}});
And you would filter them in your HTML like so:
<div class="list">
<a class="item item-divider">sticky</a>
<a class="item" ng-repeat="note in Notes | filter:{sticky: true}">
<h2>[[note.title]]</h2>
</a>
<div class="item item-divider">recent</div>
<a class="item" ng-repeat="note in Notes">
<h2>[[note.title]]</h2>
</a>
</div>
i want to display 2 different queries from notes collection.
if u know what i mean.
How do i write code such condition ?