javascript - angular common service DRY code -


lets consider following "projects" module.

the service

angular.module('srvc.projects',[]).factory('projects_fctr',function($resource){ return $resource('api/projects/:id',{id:'@_id'},{     update: { method: 'put' },      query: { method: 'get', isarray: true },     create: { method: 'post'}     }); }); 

and following controller

 projects_fctr.query( function (data) {      if (!data.error) {         $scope.projects = data;         notify({ messagetemplate: $scope.notifymsg.res, classes: 'alert-success', duration: 3000});      } else {         notify({ messagetemplate: $scope.notifymsg.ree, classes: 'alert-warning'});     }  }); 

which both work fine.

i noticing if want create "clients" module, have duplicate above code , change references "projects" "clients".

the results having multiple "versions" of same services/controllers, 1 each module.

is there way make dry service & controller can used "whatever" module. cut down amount of code needed.

i using ui-router.

any thoughts?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -