If you look at the Wire up a Backend Server Communication example on angularjs.org the mongolab module seems reusable except for the hardcoded $resource path and key:
angular.module('mongolab', ['ngResource']).
factory('Project', function($resource) {
var Project = $resource('https://api.mongolab.com/api/1/databases' +
'/angularjs/collections/projects/:id',
{ apiKey: '4f847ad3e4b08a2eed5f3b54' }, {
update: { method: 'PUT' }
}
);
...
Here is the route:
when('/edit/:projectId', {controller:EditCtrl, templateUrl:'detail.html'})
In many situations, if I can change the db path in the angular service based on the route, I could easily reuse the service module and the controller. I'd like to pass the $resource path + other info into the controller something like this:
when('/edit/:projectId',
{
controller:EditCtrl,
templateUrl:'detail.html'
dbroute: 'https://api.mongolab.com/api/1/databases'...
apiKey: 'querystring,info,the,$resource,needs'
})
when('/otheredit/:projectId',
{
controller:EditCtrl,
templateUrl:'otherdetail.html'
dbroute: 'https://other_route_to_database'...
otherinfo: 'other,querystring,info,the,$resource,needs'
})
My goal is to reuse EditCtrl and mongolab when I can or use something like simple inheritance to reuse most of it. Otherwise I'll end up typing this code over and over again.
Thoughts?