@@ -45,9 +45,11 @@ <h3><p><code><span class="pln">save( :docs );</span></code></p></h3>
45
45
< a href ="" class ="label type-hint type-hint-object "> object</ a >
46
46
</ td >
47
47
< td > < p > The docs to save to the Meteor Collection.
48
- If nothing is passed, the method saves everything in the AngularMeteorCollection as is.
49
- If an object is passed, the method pushes that object into the AngularMeteorCollection.
50
- If an array is passed, the method pushes that all objects in the array into the AngularMeteorCollection.
48
+ < ul >
49
+ < li > If nothing is passed, the method saves everything in the AngularMeteorCollection as is.</ li >
50
+ < li > If an object is passed, the method pushes that object into the AngularMeteorCollection.</ li >
51
+ < li > If an array of objects is passed, the method pushes all objects into the AngularMeteorCollection.</ li >
52
+ </ ul >
51
53
</ p > </ td >
52
54
< td > < a href ="" class ="label type-hint type-hint-object "> No</ a > </ td >
53
55
</ tr >
@@ -87,9 +89,11 @@ <h4>Parameters</h4>
87
89
< a href ="" class ="label type-hint type-hint-object "> object</ a >
88
90
</ td >
89
91
< td > < p > The keys of the object to remove from the Meteor Collection.
90
- If nothing is passed, the method removes all the documents from the AngularMeteorCollection.
91
- If an object is passed, the method removes the object with that key from the AngularMeteorCollection.
92
- If an array is passed, the method removes all objects that matches the keys in the array from the AngularMeteorCollection.
92
+ < ul >
93
+ < li > If nothing is passed, the method removes all the documents from the AngularMeteorCollection.</ li >
94
+ < li > If an object is passed, the method removes the object with that key from the AngularMeteorCollection.</ li >
95
+ < li > If an array is passed, the method removes all objects that matches the keys in the array from the AngularMeteorCollection.</ li >
96
+ </ li >
93
97
</ p > </ td >
94
98
< td > < a href ="" class ="label type-hint type-hint-object "> No</ a > </ td >
95
99
</ tr >
@@ -107,9 +111,9 @@ <h4>Parameters</h4>
107
111
< br >
108
112
< h3 > < p > < code > < span class ="pln "> subscribe( :subscriptionName );</ span > </ code > </ p > </ h3 >
109
113
< br >
110
- A shorten (Syntactic sugar) function for the < a href ="/api/subscribe "> $meteor.subscribe function </ a > .
114
+ A shorter ('syntactic sugar' ) function for < a href ="/api/subscribe "> $meteor.subscribe</ a > .
111
115
112
- Takes only one parameter and not returns a promise like < a href ="/api/subscribe "> $meteor.subscribe</ a > does.
116
+ Takes only one parameter and doesn't return a promise like < a href ="/api/subscribe "> $meteor.subscribe</ a > does.
113
117
114
118
When called after $scope.meteorCollection, it acts the same but in addition it automatically closes the subscription when the scope is destroyed.
115
119
@@ -130,7 +134,7 @@ <h4>Parameters</h4>
130
134
< td >
131
135
< a href ="" class ="label type-hint type-hint-string "> subscriptionName</ a >
132
136
</ td >
133
- < td > < p > The subscription name to subscribe to. exactly like the first parameter in $meteor.subscribe service.
137
+ < td > < p > The subscription name to subscribe to. Exactly like the first parameter in the $meteor.subscribe service.
134
138
</ p > </ td >
135
139
< td > < a href ="" class ="label type-hint type-hint-object "> Yes</ a > </ td >
136
140
</ tr >
@@ -141,7 +145,7 @@ <h4>Parameters</h4>
141
145
< br >
142
146
< h3 > < p > < code > < span class ="pln "> stop();</ span > </ code > </ p > </ h3 >
143
147
< br >
144
- Stops watching the current collection for changes made in the scope variable or the meteor collection.
148
+ Stops watching the current collection for changes made in the scope variable or meteor collection.
145
149
146
150
#### Parameters
147
151
None
@@ -154,32 +158,57 @@ <h3><p><code><span class="pln">stop();</span></code></p></h3>
154
158
// Bind all the todos to $scope.todos without auto-save
155
159
$scope.todos = $meteor.collection(Todos, false);
156
160
161
+ // Add a single todo to the collection
157
162
var todoObject = {name:'first todo'};
158
- var todoArray = [{name:'second todo'}, {name:'third todo'}];
159
- var todoSecondObject = {name:'forth todo'};
160
-
161
163
$scope.todos.save(todoObject); // todos equals [{name:'first todo'}]
162
164
165
+ // Add multiple todos to the collection
166
+ var todoArray = [{name:'second todo'}, {name:'third todo'}];
163
167
$scope.todos.save(todosArray); // todos equals [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}]
164
168
165
- $scope.todos.push(todoSecondObject); // The scope variable equals to [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}, {name:'forth todo'}]
166
- // but the collection still equals to [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}]
167
-
168
- $scope.todos.save(); // Now the collection also equals to [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}, {name:'forth todo'}]
169
-
170
- $scope.todos.remove(firstTodoId); // scope and collection equals to [{name:'second todo'}, {name:'third todo'}, {name:'forth todo'}]
169
+ // Add another todo to the collection
170
+ var anotherTodoObject = {name:'fourth todo'};
171
+ $scope.todos.push(anotherTodoObject);
172
+
173
+ /*
174
+ * The scope variable now holds:
175
+ * [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}, {name:'fourth todo'}]
176
+ *
177
+ * but the collection holds:
178
+ * [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}]
179
+ *
180
+ * that's because auto-save was set to false (the 2nd parameter in the $meteor.collection call).
181
+ *
182
+ * To save the data we need to explicitly call the save() function:
183
+ */
184
+ $scope.todos.save();
185
+
186
+ $scope.todos.remove(firstTodoId); // scope and collection equals to [{name:'second todo'}, {name:'third todo'}, {name:'fourth todo'}]
171
187
172
188
$scope.todos.remove(todoIdsArray); // removes everything matches the array of IDs both in scope and in collection
173
189
174
190
$scope.todos.pop(); // removes only in scope
175
191
176
192
$scope.todos.remove(); // syncs also in Meteor collection
177
193
178
-
179
194
// Using the subscribe function
180
195
$scope.parties = $meteor.collection(Parties).subscribe('partiesSubscription');
181
196
197
+ // With a callback to do something after the todo was saved and to catch errors
198
+ $scope.todos.save(todoObject)
199
+ .then( function() {
200
+
201
+ // todos were successfully saved
202
+ console.log('The todo was saved');
203
+
204
+ }, function(err) {
205
+
206
+ // an error occurred while saving the todos: maybe you're not authorized
207
+ console.error( 'An error occurred. The error message is: ' + err.message);
208
+
209
+ });
182
210
{{/markdown}}
211
+
183
212
</ do-nothing >
184
213
185
214
</ div >
0 commit comments