|
52 | 52 | Notice that this code runs outside of the isClient statement.
|
53 | 53 | That means that this collection and the actions on it will run both on the client (minimongo) and the server (Mongo) and Meteor will take care of syncing them both.
|
54 | 54 |
|
55 |
| -Now that we've created the collection, our client needs to subscribe to it's changes. |
56 |
| -We do this with the Meteor.subscribe function: |
57 |
| - |
58 |
| -Add |
59 |
| - |
60 |
| - Meteor.subscribe("parties"); |
61 |
| - |
62 |
| -Inside the PartiesListCtrl controller. |
63 |
| - |
64 |
| - |
65 |
| -So now, we have a parties Meteor collection and a parties AngularJS collection, but they are not binded to each other. |
| 55 | +Now that we've created the collection, our client needs to subscribe to it's changes and bind it to our parties AngularJS collection. |
66 | 56 |
|
67 | 57 | To bind them we are going to use angular-meteor built-in [service](https://docs.angularjs.org/guide/services) called $collection.
|
68 | 58 |
|
69 |
| -We are going to replace the declaration of $scope.parties with the following command: |
| 59 | +The $collection.bind function will not only bind but also subscribe to the parties Mongo collection. |
| 60 | + |
| 61 | +We are going to replace the declaration of $scope.parties with the following command inside the PartiesListCtrl controller: |
70 | 62 |
|
71 |
| - $collection(Parties).bind($scope, 'parties', true); |
| 63 | + $collection(Parties).bind($scope, 'parties', true, true); |
72 | 64 |
|
73 | 65 | That line declares a new $scope.parties variable so we don't need to do something like $scope.parties = []; and then binds it to the Parties Mongo collection.
|
74 | 66 |
|
|
91 | 83 | angular.module("socially").controller("PartiesListCtrl", ['$scope', '$collection',
|
92 | 84 | function($scope, $collection){
|
93 | 85 |
|
94 |
| - Meteor.subscribe("parties"); |
95 |
| - $collection(Parties).bind($scope, 'parties', true); |
| 86 | + $collection(Parties).bind($scope, 'parties', true, true); |
96 | 87 |
|
97 | 88 | }]);
|
98 | 89 | }
|
|
0 commit comments