Skip to content

Instantly share code, notes, and snippets.

@chantastic
Created Aug 1, 2013
Embed
What would you like to do?
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