You should only use the provider recipe when you want to open the API for the entire application configuration that must be completed before the application starts. This is usually only interesting for reusable services, the behavior of which may vary slightly between applications.
var app = angular.module('mongolab', ['ngResource']) app.provider('project', function projectProvider(){ var resourceUrl = false; this.resourceUrl = function(url){ this.resourceUrl = url; } this.$get = [function project(){ return new Project(resourceUrl); }]; }); function Project(resourceUrl) { var Project = $resource(resourceUrl, { apiKey: '4f847ad3e4b08a2eed5f3b54' }, { 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; });
Then you can configure it with
app.config(["projectProvider", function(projectProvider){ projectProvider.resourceUrl('https://api.mongolab.com/api/1/databases' + '/angularjs/collections/projects/:id') }]);
source share