angular-resource.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /**
  2. * @license AngularJS v1.2.21
  3. * (c) 2010-2014 Google, Inc. http://angularjs.org
  4. * License: MIT
  5. */
  6. (function(window, angular, undefined) {'use strict';
  7. var $resourceMinErr = angular.$$minErr('$resource');
  8. // Helper functions and regex to lookup a dotted path on an object
  9. // stopping at undefined/null. The path must be composed of ASCII
  10. // identifiers (just like $parse)
  11. var MEMBER_NAME_REGEX = /^(\.[a-zA-Z_$][0-9a-zA-Z_$]*)+$/;
  12. function isValidDottedPath(path) {
  13. return (path != null && path !== '' && path !== 'hasOwnProperty' &&
  14. MEMBER_NAME_REGEX.test('.' + path));
  15. }
  16. function lookupDottedPath(obj, path) {
  17. if (!isValidDottedPath(path)) {
  18. throw $resourceMinErr('badmember', 'Dotted member path "@{0}" is invalid.', path);
  19. }
  20. var keys = path.split('.');
  21. for (var i = 0, ii = keys.length; i < ii && obj !== undefined; i++) {
  22. var key = keys[i];
  23. obj = (obj !== null) ? obj[key] : undefined;
  24. }
  25. return obj;
  26. }
  27. /**
  28. * Create a shallow copy of an object and clear other fields from the destination
  29. */
  30. function shallowClearAndCopy(src, dst) {
  31. dst = dst || {};
  32. angular.forEach(dst, function(value, key){
  33. delete dst[key];
  34. });
  35. for (var key in src) {
  36. if (src.hasOwnProperty(key) && !(key.charAt(0) === '$' && key.charAt(1) === '$')) {
  37. dst[key] = src[key];
  38. }
  39. }
  40. return dst;
  41. }
  42. /**
  43. * @ngdoc module
  44. * @name ngResource
  45. * @description
  46. *
  47. * # ngResource
  48. *
  49. * The `ngResource` module provides interaction support with RESTful services
  50. * via the $resource service.
  51. *
  52. *
  53. * <div doc-module-components="ngResource"></div>
  54. *
  55. * See {@link ngResource.$resource `$resource`} for usage.
  56. */
  57. /**
  58. * @ngdoc service
  59. * @name $resource
  60. * @requires $http
  61. *
  62. * @description
  63. * A factory which creates a resource object that lets you interact with
  64. * [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
  65. *
  66. * The returned resource object has action methods which provide high-level behaviors without
  67. * the need to interact with the low level {@link ng.$http $http} service.
  68. *
  69. * Requires the {@link ngResource `ngResource`} module to be installed.
  70. *
  71. * @param {string} url A parametrized URL template with parameters prefixed by `:` as in
  72. * `/user/:username`. If you are using a URL with a port number (e.g.
  73. * `http://example.com:8080/api`), it will be respected.
  74. *
  75. * If you are using a url with a suffix, just add the suffix, like this:
  76. * `$resource('http://example.com/resource.json')` or `$resource('http://example.com/:id.json')`
  77. * or even `$resource('http://example.com/resource/:resource_id.:format')`
  78. * If the parameter before the suffix is empty, :resource_id in this case, then the `/.` will be
  79. * collapsed down to a single `.`. If you need this sequence to appear and not collapse then you
  80. * can escape it with `/\.`.
  81. *
  82. * @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in
  83. * `actions` methods. If any of the parameter value is a function, it will be executed every time
  84. * when a param value needs to be obtained for a request (unless the param was overridden).
  85. *
  86. * Each key value in the parameter object is first bound to url template if present and then any
  87. * excess keys are appended to the url search query after the `?`.
  88. *
  89. * Given a template `/path/:verb` and parameter `{verb:'greet', salutation:'Hello'}` results in
  90. * URL `/path/greet?salutation=Hello`.
  91. *
  92. * If the parameter value is prefixed with `@` then the value of that parameter will be taken
  93. * from the corresponding key on the data object (useful for non-GET operations).
  94. *
  95. * @param {Object.<Object>=} actions Hash with declaration of custom action that should extend
  96. * the default set of resource actions. The declaration should be created in the format of {@link
  97. * ng.$http#usage_parameters $http.config}:
  98. *
  99. * {action1: {method:?, params:?, isArray:?, headers:?, ...},
  100. * action2: {method:?, params:?, isArray:?, headers:?, ...},
  101. * ...}
  102. *
  103. * Where:
  104. *
  105. * - **`action`** – {string} – The name of action. This name becomes the name of the method on
  106. * your resource object.
  107. * - **`method`** – {string} – Case insensitive HTTP method (e.g. `GET`, `POST`, `PUT`,
  108. * `DELETE`, `JSONP`, etc).
  109. * - **`params`** – {Object=} – Optional set of pre-bound parameters for this action. If any of
  110. * the parameter value is a function, it will be executed every time when a param value needs to
  111. * be obtained for a request (unless the param was overridden).
  112. * - **`url`** – {string} – action specific `url` override. The url templating is supported just
  113. * like for the resource-level urls.
  114. * - **`isArray`** – {boolean=} – If true then the returned object for this action is an array,
  115. * see `returns` section.
  116. * - **`transformRequest`** –
  117. * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
  118. * transform function or an array of such functions. The transform function takes the http
  119. * request body and headers and returns its transformed (typically serialized) version.
  120. * - **`transformResponse`** –
  121. * `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
  122. * transform function or an array of such functions. The transform function takes the http
  123. * response body and headers and returns its transformed (typically deserialized) version.
  124. * - **`cache`** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the
  125. * GET request, otherwise if a cache instance built with
  126. * {@link ng.$cacheFactory $cacheFactory}, this cache will be used for
  127. * caching.
  128. * - **`timeout`** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise} that
  129. * should abort the request when resolved.
  130. * - **`withCredentials`** - `{boolean}` - whether to set the `withCredentials` flag on the
  131. * XHR object. See
  132. * [requests with credentials](https://developer.mozilla.org/en/http_access_control#section_5)
  133. * for more information.
  134. * - **`responseType`** - `{string}` - see
  135. * [requestType](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType).
  136. * - **`interceptor`** - `{Object=}` - The interceptor object has two optional methods -
  137. * `response` and `responseError`. Both `response` and `responseError` interceptors get called
  138. * with `http response` object. See {@link ng.$http $http interceptors}.
  139. *
  140. * @returns {Object} A resource "class" object with methods for the default set of resource actions
  141. * optionally extended with custom `actions`. The default set contains these actions:
  142. * ```js
  143. * { 'get': {method:'GET'},
  144. * 'save': {method:'POST'},
  145. * 'query': {method:'GET', isArray:true},
  146. * 'remove': {method:'DELETE'},
  147. * 'delete': {method:'DELETE'} };
  148. * ```
  149. *
  150. * Calling these methods invoke an {@link ng.$http} with the specified http method,
  151. * destination and parameters. When the data is returned from the server then the object is an
  152. * instance of the resource class. The actions `save`, `remove` and `delete` are available on it
  153. * as methods with the `$` prefix. This allows you to easily perform CRUD operations (create,
  154. * read, update, delete) on server-side data like this:
  155. * ```js
  156. * var User = $resource('/user/:userId', {userId:'@id'});
  157. * var user = User.get({userId:123}, function() {
  158. * user.abc = true;
  159. * user.$save();
  160. * });
  161. * ```
  162. *
  163. * It is important to realize that invoking a $resource object method immediately returns an
  164. * empty reference (object or array depending on `isArray`). Once the data is returned from the
  165. * server the existing reference is populated with the actual data. This is a useful trick since
  166. * usually the resource is assigned to a model which is then rendered by the view. Having an empty
  167. * object results in no rendering, once the data arrives from the server then the object is
  168. * populated with the data and the view automatically re-renders itself showing the new data. This
  169. * means that in most cases one never has to write a callback function for the action methods.
  170. *
  171. * The action methods on the class object or instance object can be invoked with the following
  172. * parameters:
  173. *
  174. * - HTTP GET "class" actions: `Resource.action([parameters], [success], [error])`
  175. * - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
  176. * - non-GET instance actions: `instance.$action([parameters], [success], [error])`
  177. *
  178. * Success callback is called with (value, responseHeaders) arguments. Error callback is called
  179. * with (httpResponse) argument.
  180. *
  181. * Class actions return empty instance (with additional properties below).
  182. * Instance actions return promise of the action.
  183. *
  184. * The Resource instances and collection have these additional properties:
  185. *
  186. * - `$promise`: the {@link ng.$q promise} of the original server interaction that created this
  187. * instance or collection.
  188. *
  189. * On success, the promise is resolved with the same resource instance or collection object,
  190. * updated with data from server. This makes it easy to use in
  191. * {@link ngRoute.$routeProvider resolve section of $routeProvider.when()} to defer view
  192. * rendering until the resource(s) are loaded.
  193. *
  194. * On failure, the promise is resolved with the {@link ng.$http http response} object, without
  195. * the `resource` property.
  196. *
  197. * If an interceptor object was provided, the promise will instead be resolved with the value
  198. * returned by the interceptor.
  199. *
  200. * - `$resolved`: `true` after first server interaction is completed (either with success or
  201. * rejection), `false` before that. Knowing if the Resource has been resolved is useful in
  202. * data-binding.
  203. *
  204. * @example
  205. *
  206. * # Credit card resource
  207. *
  208. * ```js
  209. // Define CreditCard class
  210. var CreditCard = $resource('/user/:userId/card/:cardId',
  211. {userId:123, cardId:'@id'}, {
  212. charge: {method:'POST', params:{charge:true}}
  213. });
  214. // We can retrieve a collection from the server
  215. var cards = CreditCard.query(function() {
  216. // GET: /user/123/card
  217. // server returns: [ {id:456, number:'1234', name:'Smith'} ];
  218. var card = cards[0];
  219. // each item is an instance of CreditCard
  220. expect(card instanceof CreditCard).toEqual(true);
  221. card.name = "J. Smith";
  222. // non GET methods are mapped onto the instances
  223. card.$save();
  224. // POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'}
  225. // server returns: {id:456, number:'1234', name: 'J. Smith'};
  226. // our custom method is mapped as well.
  227. card.$charge({amount:9.99});
  228. // POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'}
  229. });
  230. // we can create an instance as well
  231. var newCard = new CreditCard({number:'0123'});
  232. newCard.name = "Mike Smith";
  233. newCard.$save();
  234. // POST: /user/123/card {number:'0123', name:'Mike Smith'}
  235. // server returns: {id:789, number:'0123', name: 'Mike Smith'};
  236. expect(newCard.id).toEqual(789);
  237. * ```
  238. *
  239. * The object returned from this function execution is a resource "class" which has "static" method
  240. * for each action in the definition.
  241. *
  242. * Calling these methods invoke `$http` on the `url` template with the given `method`, `params` and
  243. * `headers`.
  244. * When the data is returned from the server then the object is an instance of the resource type and
  245. * all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
  246. * operations (create, read, update, delete) on server-side data.
  247. ```js
  248. var User = $resource('/user/:userId', {userId:'@id'});
  249. User.get({userId:123}, function(user) {
  250. user.abc = true;
  251. user.$save();
  252. });
  253. ```
  254. *
  255. * It's worth noting that the success callback for `get`, `query` and other methods gets passed
  256. * in the response that came from the server as well as $http header getter function, so one
  257. * could rewrite the above example and get access to http headers as:
  258. *
  259. ```js
  260. var User = $resource('/user/:userId', {userId:'@id'});
  261. User.get({userId:123}, function(u, getResponseHeaders){
  262. u.abc = true;
  263. u.$save(function(u, putResponseHeaders) {
  264. //u => saved user object
  265. //putResponseHeaders => $http header getter
  266. });
  267. });
  268. ```
  269. *
  270. * You can also access the raw `$http` promise via the `$promise` property on the object returned
  271. *
  272. ```
  273. var User = $resource('/user/:userId', {userId:'@id'});
  274. User.get({userId:123})
  275. .$promise.then(function(user) {
  276. $scope.user = user;
  277. });
  278. ```
  279. * # Creating a custom 'PUT' request
  280. * In this example we create a custom method on our resource to make a PUT request
  281. * ```js
  282. * var app = angular.module('app', ['ngResource', 'ngRoute']);
  283. *
  284. * // Some APIs expect a PUT request in the format URL/object/ID
  285. * // Here we are creating an 'update' method
  286. * app.factory('Notes', ['$resource', function($resource) {
  287. * return $resource('/notes/:id', null,
  288. * {
  289. * 'update': { method:'PUT' }
  290. * });
  291. * }]);
  292. *
  293. * // In our controller we get the ID from the URL using ngRoute and $routeParams
  294. * // We pass in $routeParams and our Notes factory along with $scope
  295. * app.controller('NotesCtrl', ['$scope', '$routeParams', 'Notes',
  296. function($scope, $routeParams, Notes) {
  297. * // First get a note object from the factory
  298. * var note = Notes.get({ id:$routeParams.id });
  299. * $id = note.id;
  300. *
  301. * // Now call update passing in the ID first then the object you are updating
  302. * Notes.update({ id:$id }, note);
  303. *
  304. * // This will PUT /notes/ID with the note object in the request payload
  305. * }]);
  306. * ```
  307. */
  308. angular.module('ngResource', ['ng']).
  309. factory('$resource', ['$http', '$q', function($http, $q) {
  310. var DEFAULT_ACTIONS = {
  311. 'get': {method:'GET'},
  312. 'save': {method:'POST'},
  313. 'query': {method:'GET', isArray:true},
  314. 'remove': {method:'DELETE'},
  315. 'delete': {method:'DELETE'}
  316. };
  317. var noop = angular.noop,
  318. forEach = angular.forEach,
  319. extend = angular.extend,
  320. copy = angular.copy,
  321. isFunction = angular.isFunction;
  322. /**
  323. * We need our custom method because encodeURIComponent is too aggressive and doesn't follow
  324. * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
  325. * segments:
  326. * segment = *pchar
  327. * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
  328. * pct-encoded = "%" HEXDIG HEXDIG
  329. * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
  330. * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
  331. * / "*" / "+" / "," / ";" / "="
  332. */
  333. function encodeUriSegment(val) {
  334. return encodeUriQuery(val, true).
  335. replace(/%26/gi, '&').
  336. replace(/%3D/gi, '=').
  337. replace(/%2B/gi, '+');
  338. }
  339. /**
  340. * This method is intended for encoding *key* or *value* parts of query component. We need a
  341. * custom method because encodeURIComponent is too aggressive and encodes stuff that doesn't
  342. * have to be encoded per http://tools.ietf.org/html/rfc3986:
  343. * query = *( pchar / "/" / "?" )
  344. * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
  345. * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
  346. * pct-encoded = "%" HEXDIG HEXDIG
  347. * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
  348. * / "*" / "+" / "," / ";" / "="
  349. */
  350. function encodeUriQuery(val, pctEncodeSpaces) {
  351. return encodeURIComponent(val).
  352. replace(/%40/gi, '@').
  353. replace(/%3A/gi, ':').
  354. replace(/%24/g, '$').
  355. replace(/%2C/gi, ',').
  356. replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
  357. }
  358. function Route(template, defaults) {
  359. this.template = template;
  360. this.defaults = defaults || {};
  361. this.urlParams = {};
  362. }
  363. Route.prototype = {
  364. setUrlParams: function(config, params, actionUrl) {
  365. var self = this,
  366. url = actionUrl || self.template,
  367. val,
  368. encodedVal;
  369. var urlParams = self.urlParams = {};
  370. forEach(url.split(/\W/), function(param){
  371. if (param === 'hasOwnProperty') {
  372. throw $resourceMinErr('badname', "hasOwnProperty is not a valid parameter name.");
  373. }
  374. if (!(new RegExp("^\\d+$").test(param)) && param &&
  375. (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
  376. urlParams[param] = true;
  377. }
  378. });
  379. url = url.replace(/\\:/g, ':');
  380. params = params || {};
  381. forEach(self.urlParams, function(_, urlParam){
  382. val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
  383. if (angular.isDefined(val) && val !== null) {
  384. encodedVal = encodeUriSegment(val);
  385. url = url.replace(new RegExp(":" + urlParam + "(\\W|$)", "g"), function(match, p1) {
  386. return encodedVal + p1;
  387. });
  388. } else {
  389. url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W|$)", "g"), function(match,
  390. leadingSlashes, tail) {
  391. if (tail.charAt(0) == '/') {
  392. return tail;
  393. } else {
  394. return leadingSlashes + tail;
  395. }
  396. });
  397. }
  398. });
  399. // strip trailing slashes and set the url
  400. url = url.replace(/\/+$/, '') || '/';
  401. // then replace collapse `/.` if found in the last URL path segment before the query
  402. // E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
  403. url = url.replace(/\/\.(?=\w+($|\?))/, '.');
  404. // replace escaped `/\.` with `/.`
  405. config.url = url.replace(/\/\\\./, '/.');
  406. // set params - delegate param encoding to $http
  407. forEach(params, function(value, key){
  408. if (!self.urlParams[key]) {
  409. config.params = config.params || {};
  410. config.params[key] = value;
  411. }
  412. });
  413. }
  414. };
  415. function resourceFactory(url, paramDefaults, actions) {
  416. var route = new Route(url);
  417. actions = extend({}, DEFAULT_ACTIONS, actions);
  418. function extractParams(data, actionParams){
  419. var ids = {};
  420. actionParams = extend({}, paramDefaults, actionParams);
  421. forEach(actionParams, function(value, key){
  422. if (isFunction(value)) { value = value(); }
  423. ids[key] = value && value.charAt && value.charAt(0) == '@' ?
  424. lookupDottedPath(data, value.substr(1)) : value;
  425. });
  426. return ids;
  427. }
  428. function defaultResponseInterceptor(response) {
  429. return response.resource;
  430. }
  431. function Resource(value){
  432. shallowClearAndCopy(value || {}, this);
  433. }
  434. forEach(actions, function(action, name) {
  435. var hasBody = /^(POST|PUT|PATCH)$/i.test(action.method);
  436. Resource[name] = function(a1, a2, a3, a4) {
  437. var params = {}, data, success, error;
  438. /* jshint -W086 */ /* (purposefully fall through case statements) */
  439. switch(arguments.length) {
  440. case 4:
  441. error = a4;
  442. success = a3;
  443. //fallthrough
  444. case 3:
  445. case 2:
  446. if (isFunction(a2)) {
  447. if (isFunction(a1)) {
  448. success = a1;
  449. error = a2;
  450. break;
  451. }
  452. success = a2;
  453. error = a3;
  454. //fallthrough
  455. } else {
  456. params = a1;
  457. data = a2;
  458. success = a3;
  459. break;
  460. }
  461. case 1:
  462. if (isFunction(a1)) success = a1;
  463. else if (hasBody) data = a1;
  464. else params = a1;
  465. break;
  466. case 0: break;
  467. default:
  468. throw $resourceMinErr('badargs',
  469. "Expected up to 4 arguments [params, data, success, error], got {0} arguments",
  470. arguments.length);
  471. }
  472. /* jshint +W086 */ /* (purposefully fall through case statements) */
  473. var isInstanceCall = this instanceof Resource;
  474. var value = isInstanceCall ? data : (action.isArray ? [] : new Resource(data));
  475. var httpConfig = {};
  476. var responseInterceptor = action.interceptor && action.interceptor.response ||
  477. defaultResponseInterceptor;
  478. var responseErrorInterceptor = action.interceptor && action.interceptor.responseError ||
  479. undefined;
  480. forEach(action, function(value, key) {
  481. if (key != 'params' && key != 'isArray' && key != 'interceptor') {
  482. httpConfig[key] = copy(value);
  483. }
  484. });
  485. if (hasBody) httpConfig.data = data;
  486. route.setUrlParams(httpConfig,
  487. extend({}, extractParams(data, action.params || {}), params),
  488. action.url);
  489. var promise = $http(httpConfig).then(function (response) {
  490. var data = response.data,
  491. promise = value.$promise;
  492. if (data) {
  493. // Need to convert action.isArray to boolean in case it is undefined
  494. // jshint -W018
  495. if (angular.isArray(data) !== (!!action.isArray)) {
  496. throw $resourceMinErr('badcfg',
  497. 'Error in resource configuration. Expected ' +
  498. 'response to contain an {0} but got an {1}',
  499. action.isArray ? 'array' : 'object',
  500. angular.isArray(data) ? 'array' : 'object');
  501. }
  502. // jshint +W018
  503. if (action.isArray) {
  504. value.length = 0;
  505. forEach(data, function (item) {
  506. if (typeof item === "object") {
  507. value.push(new Resource(item));
  508. } else {
  509. // Valid JSON values may be string literals, and these should not be converted
  510. // into objects. These items will not have access to the Resource prototype
  511. // methods, but unfortunately there
  512. value.push(item);
  513. }
  514. });
  515. } else {
  516. shallowClearAndCopy(data, value);
  517. value.$promise = promise;
  518. }
  519. }
  520. value.$resolved = true;
  521. response.resource = value;
  522. return response;
  523. }, function(response) {
  524. value.$resolved = true;
  525. (error||noop)(response);
  526. return $q.reject(response);
  527. });
  528. promise = promise.then(
  529. function(response) {
  530. var value = responseInterceptor(response);
  531. (success||noop)(value, response.headers);
  532. return value;
  533. },
  534. responseErrorInterceptor);
  535. if (!isInstanceCall) {
  536. // we are creating instance / collection
  537. // - set the initial promise
  538. // - return the instance / collection
  539. value.$promise = promise;
  540. value.$resolved = false;
  541. return value;
  542. }
  543. // instance call
  544. return promise;
  545. };
  546. Resource.prototype['$' + name] = function(params, success, error) {
  547. if (isFunction(params)) {
  548. error = success; success = params; params = {};
  549. }
  550. var result = Resource[name].call(this, params, this, success, error);
  551. return result.$promise || result;
  552. };
  553. });
  554. Resource.bind = function(additionalParamDefaults){
  555. return resourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
  556. };
  557. return Resource;
  558. }
  559. return resourceFactory;
  560. }]);
  561. })(window, window.angular);