javascript - How can i convert all factories to one factory? -
how can convert below different factories 1 factory.i confuse how implement , save method if have 1 factory.
factory.js
angular.module("app").factory('riskservice', function ($resource) { 'use strict'; return $resource('app/risk/rest/risk/:id'); }); //riskeventtypeinfo angular.module("app").factory('riskeventtypeinfo', function ($resource) { return $resource('app/risk/rest/risk/getriskeventtypeinfo/:id', {}, { 'query': { method: 'get' }, 'get': { method: 'get' } }); }); //riskcausecategoryinfo angular.module("app").factory('riskcausecategoryinfo', function ($resource) { return $resource('app/risk/rest/risk/getriskcausecategoryinfo/:id', {}, { 'query': { method: 'get' }, 'get': { method: 'get' } }); });
create factory returns object each function.
//riskfacade angular.module('app').factory('riskfacade', ['riskservice', 'riskeventtypeinfo', 'riskcausecategoryinfo', function (riskservice, riskeventtypeinfo, riskcausecategoryinfo) { return { getrisk: riskservice.get, getriskeventtype: riskeventtypeinfo.get, getriskcausecategory: riskcausecategoryinfo.get }; }]); riskfacade.getrisk({id: 123}, function () {});
the same before $http service.
angular.module('app').factory('riskfacade', ['$http', function ($http) { return { getrisk: function (id) { return $http.get('app/risk/rest/risk/' + id); }, getriskeventtype: function (id) { return $http.get('app/risk/rest/risk/getriskeventtypeinfo/' + id); }, getriskcausecategory: function (id) { return $http.get('app/risk/rest/risk/getriskcausecategoryinfo/' + id); } }; }]); //then riskfacade.getrisk(123).success(successmethod).error(errormethod);
Comments
Post a Comment