javascript - How to define AngularJs service with REST (using $resource) and other more method -
i want define more methods on same settings service other rest method have. don't know how.
var settingsservice = angular.module('settingsservice',['ngresource']); settingsservice.service('settingsservice', ['$resource', function($resource){ return $resource('http://localhost:9000/settings', {}, { update: {method:'put'}, }); }]);
how can add more method , members service? example:
var settingsservice = angular.module('settingsservice',['ngresource']); settingsservice.service('settingsservice', ['$resource', function($resource){ return $resource('http://localhost:9000/settings', {}, { update: {method:'put'}, }); var x; //some member this.func1 = function(){ // } }]);
thanks
you can write
settingsservice.service('settingsservice', ['$resource', function($resource){ var _settingsservicefactory = []; var _varx = 'somevalue'; var _functionx = function() { // }; var _resourcesrvc = function() { return $resource('http://localhost:9000/settings', {}, { update: {method:'put'}}); settingsservicefactory.varx = _varx; settingsservicefactory.functionx =_functionx ; settingsservicefactory.resourcesrvc = _resourcesrvc; return settingsservicefactory; });
or write
settingsservice.service('settingsservice', ['$resource', function($resource){ var _settingsservicefactory = { functionx = function() { // }, resourcesrvc = function() { return $resource('http://localhost:9000/settings', {}, { update: {method:'put'}}); }; return _settingsservicefactory });
either doing same thing .
Comments
Post a Comment