|
| 1 | +<template name="api.AngularMeteorCollection.html"> |
| 2 | + <div> |
| 3 | + <a href="https://github.com/Urigo/angular-meteor/edit/master/.docs/angular-meteor/client/views/api/api.AngularMeteorCollection.html" |
| 4 | + class="btn btn-default btn-lg improve-button"> |
| 5 | + <i class="glyphicon glyphicon-edit"> </i>Improve this doc |
| 6 | + </a> |
| 7 | + |
| 8 | + <do-nothing> |
| 9 | + {{#markdown}} |
| 10 | + |
| 11 | +# AngularMeteorCollection |
| 12 | + |
| 13 | +An object that connects a [Meteor Collection](http://docs.meteor.com/#/full/collections) to an AngularJS scope variable |
| 14 | + |
| 15 | +---- |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +See [bind](/api/collection-bind) and [bindOne](/api/collection-bindOne) |
| 20 | + |
| 21 | +---- |
| 22 | + |
| 23 | +## Methods |
| 24 | + |
| 25 | +<h3><p><code><span class="pln">save( :docs );</span></code></p></h3> |
| 26 | +<br> |
| 27 | + |
| 28 | +#### Parameters |
| 29 | + |
| 30 | +<table class="variables-matrix input-arguments"> |
| 31 | +<thead> |
| 32 | +<tr> |
| 33 | + <th>Param</th> |
| 34 | + <th>Type</th> |
| 35 | + <th>Details</th> |
| 36 | + <th>Required</th> |
| 37 | +</tr> |
| 38 | +</thead> |
| 39 | +<tbody> |
| 40 | +<tr> |
| 41 | + <td>docs</td> |
| 42 | + <td> |
| 43 | + <a href="" class="label type-hint type-hint-string">empty</a>/ |
| 44 | + <a href="" class="label type-hint type-hint-array">array</a>/ |
| 45 | + <a href="" class="label type-hint type-hint-object">object</a> |
| 46 | + </td> |
| 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. |
| 51 | + </p></td> |
| 52 | + <td><a href="" class="label type-hint type-hint-object">No</a></td> |
| 53 | +</tr> |
| 54 | +</tbody> |
| 55 | +</table> |
| 56 | + |
| 57 | +<br> |
| 58 | +<h3><p><code><span class="pln">remove( :keys );</span></code></p></h3> |
| 59 | +<br> |
| 60 | + |
| 61 | +#### Parameters |
| 62 | + |
| 63 | +<table class="variables-matrix input-arguments"> |
| 64 | +<thead> |
| 65 | +<tr> |
| 66 | + <th>Param</th> |
| 67 | + <th>Type</th> |
| 68 | + <th>Details</th> |
| 69 | + <th>Required</th> |
| 70 | +</tr> |
| 71 | +</thead> |
| 72 | +<tbody> |
| 73 | +<tr> |
| 74 | + <td>keys</td> |
| 75 | + <td> |
| 76 | + <a href="" class="label type-hint type-hint-string">empty</a>/ |
| 77 | + <a href="" class="label type-hint type-hint-array">array</a>/ |
| 78 | + <a href="" class="label type-hint type-hint-object">object</a> |
| 79 | + </td> |
| 80 | + <td><p>The keys of the object to remove from the Meteor Collection. |
| 81 | + If nothing is passed, the method removes all the documents from the AngularMeteorCollection. |
| 82 | + If an object is passed, the method removes the object with that key from the AngularMeteorCollection. |
| 83 | + If an array is passed, the method removes all objects that matches the keys in the array from the AngularMeteorCollection. |
| 84 | + </p></td> |
| 85 | + <td><a href="" class="label type-hint type-hint-object">No</a></td> |
| 86 | +</tr> |
| 87 | +</tbody> |
| 88 | +</table> |
| 89 | + |
| 90 | +<br> |
| 91 | + |
| 92 | +---- |
| 93 | + |
| 94 | + |
| 95 | +## Example |
| 96 | + |
| 97 | + // Bind all the todos to $scope.todos without auto-save |
| 98 | + $collection(Todos).bind($scope, 'todos'); |
| 99 | + |
| 100 | + var todoObject = {name:'first todo'}; |
| 101 | + var todoArray = [{name:'second todo'}, {name:'third todo'}]; |
| 102 | + var todoSecondObject = {name:'forth todo'}; |
| 103 | + |
| 104 | + $scope.todos.save(todoObject); // todos equals [{name:'first todo'}] |
| 105 | + |
| 106 | + $scope.todos.save(todosArray); // todos equals [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}] |
| 107 | + |
| 108 | + $scope.todos.push(todoSecondObject); // The scope variable equals to [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}, {name:'forth todo'}] |
| 109 | + // but the collection still equals to [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}] |
| 110 | + |
| 111 | + $scope.todos.save(); // Now the collection also equals to [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}, {name:'forth todo'}] |
| 112 | + |
| 113 | + $scope.todos.remove(firstTodoId); // scope and collection equals to [{name:'second todo'}, {name:'third todo'}, {name:'forth todo'}] |
| 114 | + |
| 115 | + $scope.todos.remove(todoIdsArray); // removes everything matches the array of IDs both in scope and in collection |
| 116 | + |
| 117 | + $scope.todos.pop(); // removes only in scope |
| 118 | + |
| 119 | + $scope.todos.remove(); // syncs also in Meteor collection |
| 120 | + |
| 121 | + {{/markdown}} |
| 122 | + </do-nothing> |
| 123 | + |
| 124 | + </div> |
| 125 | +</template> |
0 commit comments