-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ ng-sails | |
Installation | ||
------------ | ||
|
||
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. | ||
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. | ||
|
||
In your controller, require `$sails` and then bind the models together like so: | ||
|
||
|
@@ -15,16 +15,38 @@ In your controller, require `$sails` and then bind the models together like so: | |
sort:"id desc" | ||
}); | ||
|
||
This will establish a socket.io socket and update `$scope.model` whenever CRUD events are fired over the socket from sails. | ||
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. | ||
|
||
The third parameter is the same as the [waterline queries](https://github.com/balderdashy/waterline-docs/blob/master/query.md). | ||
|
||
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"]`. | ||
|
||
You can now use full CRUD methods on the model after it has been bound | ||
|
||
$scope.model.create({name:"Ash"}); | ||
|
||
The other CRUD methods require an ID to be the first parameter | ||
|
||
$scope.model.update(1, {name:"Ash"}); | ||
|
||
The methods are `create`, `retrieve`, `update` and `destroy`. | ||
|
||
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__. | ||
|
||
CRUD methods return promises instead of itself so you can't chain them unfortunately. | ||
|
||
Pagination | ||
---------- | ||
A quick and easy way to enable pagination is to modify the `params` object of the model returned in your angular scope. | ||
|
||
$scope.model.params.skip = 30; | ||
|
||
This will load the next set of results. | ||
|
||
Bugs | ||
---------- | ||
There is currently no way to remove named sockets with the current version of `sails.io.js`, I don't think :S | ||
|
||
Maintainer | ||
---------- | ||
Ash Taylor, [[email protected]](mailto:[email protected]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "ng-sails", | ||
"version": "0.1.0", | ||
"description": "Bind a sails model to an Angular model with full CRUD support", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/zivc/ng-sails.git" | ||
}, | ||
"keywords": [ | ||
"sailsjs", | ||
"angularjs", | ||
"sails", | ||
"angular", | ||
"socket", | ||
"socket.io" | ||
], | ||
"author": "Ash @zivcjs <[email protected]> (http://zi.vc/)", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/zivc/ng-sails/issues" | ||
}, | ||
"homepage": "https://github.com/zivc/ng-sails" | ||
} |