Skip to content

Instantly share code, notes, and snippets.

@chantastic
Created August 1, 2013 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chantastic/6132647 to your computer and use it in GitHub Desktop.
Save chantastic/6132647 to your computer and use it in GitHub Desktop.
Setting up ng-resouce in an angular app.
'use strict';
var stintApp = angular.module('stintApp', ['ui', 'ngResource'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/projects', {
templateUrl: 'views/projects.html',
controller: 'ProjectsCtrl'
})
.otherwise({
redirectTo: '/'
});
}]);
'use strict';
stintApp.factory('Project', function($resource) {
var Project = $resource('http://localhost\\:3000/api/projects',
{},
{
update: { method: 'PUT' }
}
);
Project.prototype.update = function(cb) {
return Project.update({id: this._id.$oid},
angular.extend({}, this, {_id:undefined}), cb);
};
Project.prototype.destroy = function(cb) {
return Project.remove({id: this._id.$oid}, cb);
};
return Project;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment