You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-2Lines changed: 24 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ ng-sails
5
5
Installation
6
6
------------
7
7
8
-
Include `ng-sails.js` (or `bower install ng-sails`) file into your project and don't forget to add the `ngSails` module to your modules dependencies.
8
+
Include `ng-sails.js` (or `npm install ng-sails`) file into your project and don't forget to add the `ngSails` module to your apps dependencies.
9
9
10
10
In your controller, require `$sails` and then bind the models together like so:
11
11
@@ -15,16 +15,38 @@ In your controller, require `$sails` and then bind the models together like so:
15
15
sort:"id desc"
16
16
});
17
17
18
-
This will establish a socket.io socket and update `$scope.model` whenever CRUD events are fired over the socket from sails.
18
+
This will establish a socket.io socket and update `$scope.model` whenever CRUD events are fired over the socket from sails. Changing the sort order from `"id desc"` will stop `create` events from automatically appending to the top of your model. All other events will update the model with the changes should that item exist.
19
19
20
20
The third parameter is the same as the [waterline queries](https://github.com/balderdashy/waterline-docs/blob/master/query.md).
21
21
22
22
Your actual sails model will now exist inside `$scope.model.data`. Modifying any of the `$scope.model.params` values will re-establish socket connections with those new values so be mindful when binding the model directly to an `input[type="text"]`.
23
23
24
+
You can now use full CRUD methods on the model after it has been bound
25
+
26
+
$scope.model.create({name:"Ash"});
27
+
28
+
The other CRUD methods require an ID to be the first parameter
29
+
30
+
$scope.model.update(1, {name:"Ash"});
31
+
32
+
The methods are `create`, `retrieve`, `update` and `destroy`.
33
+
34
+
You could always hook into the `$scope.model.crud()` method directly. It takes three parameters, the first being either `get`, `post`, `put` or `delete`, second being the object and third is the optional id. __This is subject to change to support waterline ORM in the future__.
35
+
36
+
CRUD methods return promises instead of itself so you can't chain them unfortunately.
37
+
24
38
Pagination
25
39
----------
26
40
A quick and easy way to enable pagination is to modify the `params` object of the model returned in your angular scope.
27
41
42
+
$scope.model.params.skip = 30;
43
+
44
+
This will load the next set of results.
45
+
46
+
Bugs
47
+
----------
48
+
There is currently no way to remove named sockets with the current version of `sails.io.js`, I don't think :S
0 commit comments