a Sails application using Angular Material
a Sails application (v0.11.0) using the latest version of Angular Material (v0.10.0)
The demo is included in this repository showing off the Grid List component.
All dependencies can be found in the assets/js/dependencies directory. This includes of:
Any angular modules placed inside this directory will be loaded after the above.
Any angular modules placed inside this directory will be loaded after the above. This order of the dependencies is kept within the assets pipeline bundled with Sails.
// Client-side javascript files to inject in order // (uses Grunt-style wildcard/glob/splat expressions) var jsFilesToInject = // Load sails.io before everything else 'js/dependencies/sails.io.js' // Dependencies like jQuery, or Angular are brought in here 'js/dependencies/angular.min.js' 'js/dependencies/angular-sails.min.js' 'js/dependencies/angular-animate.min.js' 'js/dependencies/angular-aria.min.js' 'js/dependencies/angular-material.min.js' 'js/dependencies/**/*.js' // All of the rest of your client-side js files // will be injected here in no particular order. 'js/**/*.js';All of your Angular components will be in the app.js file which is in the directory just before, assets/js/
Clone this repository, make sure you install of the require dependencies and go inside the sails-angular-material directory. You can do this in one command:
cd sails-angular-material && npm install && sails liftNow you can test out the example post api, which uses only the default create and destroy.
We let Sails do most of the work here through its Blueprint API, which makes it a perfect match for when using Angular. The API gets set up with the following command:
If your doing this from scratch and haven't cloned this repository, create a new app:
sails new appNow generate an API for "posts" which will consist of a Model, a View and a Controller:
sails generate api postsA controller will be created, found in the api/ folder.
/** * PostsController * * @description :: Server-side logic for managing posts * @help :: See http://links.sailsjs.org/docs/controllers */ moduleexports = { Posts; Posts; } ;Next is to create your model, this will be where your business logic resides:
/*** Posts.js** @description :: TODO: You might write a short summary of how this model works and what it represents here.* @docs :: http://sailsjs.org/#!documentation/models*/ moduleexports = attributes: r: type: "integer" required: true c: type: "integer" required: true color: type: "string" required: true name: type: "string" unique: true ;We then use angular-sails on the front end for use of web sockets.
$sails.get("/posts") for the first time and attach it to the $scope. { $sails ; $sails; };Now we can start to perform actions with Angular like destroying or creating a record:
$scope { var req = method: 'POST' url: '/posts/create' data: newPost ; ; }; $scope { if typeof postId === 'number' var req = method: 'POST' url: '/posts/destroy?id=' + postId ; ; };The Angular Material Grid List is used to display the posts via this code here:
#{{$index}} {{post.name}}: ({{post.r}}r x {{post.c}}c) If you would like to contribute to this repository, feel free!