Reputation: 1398
Let say we need to show filtered tasks on view, first step we got all the list of tasks buy publishing/subscribing:
Publish:
Meteor.publish("tasks", function(options){
return Tasks.find(options);
});
Subscribe:
var allTasks = $meteor.collection(Tasks).subscribe('tasks', {});
And now, let say I need to see in $scope only tasks that have 'active' variable set to true.
Something like this:
$scope.active_tasks = getFilteredTasks(allTasks, {active: true})
How do I replace the getFilteredTasks(allTasks, {active: true}) to get tasks that have only active==true variable?
I know that we can set 'options' when subscribing to tasks like:
{active: true}
But it isn't helps to resolve the issue. The goal is to subscribe only once and later use filters to show only part of tasks.
I still not finished the Angular-Meteor tutorial, so it may be explained later, if you can please point me on right tutorial it will greatly speed-up my learning.
Thanks in advance.
Upvotes: 0
Views: 211
Reputation: 282
@pumych solution is a valid one. You could also use
$scope.$meteorSubscribe ('tasks');
$scope.activeTasks = $meteor.collection (function (){
// active tasks will only be the filtered result
return Tasks.find (active: true) ;
});
Read about data flows in Angular Meteor here https://medium.com/@tally_b/coll-pub-sub-with-angular-meteor-cb13fe48f5701. Check out the example and github code for more details.
Upvotes: 1
Reputation: 1398
OK. It looks like the solution is on Angular side. So in controller we get all the tasks:
$scope.active_tasks = $meteor.collection(Tasks);
And on view side we filter them:
<input ng-model="freeText">
<tr ng-repeat="task in active_tasks | filter:freeText ">
<td>{{ task }}</td>
</tr>
:)
Upvotes: 2