Skip to content

Commit 8e345c6

Browse files
committed
fixed some stuff
1 parent faa22c8 commit 8e345c6

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ng-sails
55
Installation
66
------------
77

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.
99

1010
In your controller, require `$sails` and then bind the models together like so:
1111

@@ -15,16 +15,38 @@ In your controller, require `$sails` and then bind the models together like so:
1515
sort:"id desc"
1616
});
1717

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.
1919

2020
The third parameter is the same as the [waterline queries](https://github.com/balderdashy/waterline-docs/blob/master/query.md).
2121

2222
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"]`.
2323

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+
2438
Pagination
2539
----------
2640
A quick and easy way to enable pagination is to modify the `params` object of the model returned in your angular scope.
2741

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
49+
2850
Maintainer
2951
----------
3052

ng-sails.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ angular.module('ngSails', []).factory('$sails', ['$q',
5050
$sails.prototype.crud = function(method, object, id) {
5151
var q = $q.defer();
5252
object = object || {};
53+
method = (typeof method == "string" ? method : 'get').toLowerCase();
5354
io.socket[method](this.prefix+this.model+(id ? '/'+id : ''), object, function(data,response) {
5455
var verb = false;
5556
switch (method) {

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "ng-sails",
3+
"version": "0.1.0",
4+
"description": "Bind a sails model to an Angular model with full CRUD support",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/zivc/ng-sails.git"
8+
},
9+
"keywords": [
10+
"sailsjs",
11+
"angularjs",
12+
"sails",
13+
"angular",
14+
"socket",
15+
"socket.io"
16+
],
17+
"author": "Ash @zivcjs <[email protected]> (http://zi.vc/)",
18+
"license": "ISC",
19+
"bugs": {
20+
"url": "https://github.com/zivc/ng-sails/issues"
21+
},
22+
"homepage": "https://github.com/zivc/ng-sails"
23+
}

0 commit comments

Comments
 (0)