Skip to content

Commit 140820f

Browse files
yilinglugkalpak
authored andcommitted
docs($resourceProvider): provide info and example for configuring $resourceProvider
1 parent 146dad7 commit 140820f

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/ngResource/resource.js

+64
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ function shallowClearAndCopy(src, dst) {
5757
* <div doc-module-components="ngResource"></div>
5858
*
5959
* See {@link ngResource.$resource `$resource`} for usage.
60+
*
61+
* See {@link ngResource.$resourceProvider `$resourceProvider`} for usage.
62+
*/
63+
64+
/**
65+
* @ngdoc provider
66+
* @name $resourceProvider
67+
*
68+
* @description
69+
*
70+
* Use for configuring {@link ngResource.$resource `$resource`} in module configuration phase.
71+
*
72+
* ## Example
73+
* See {@link ngResource.$resourceProvider#defaults `Properties`} for configuring `ngResource`.
74+
*
75+
* ## Dependencies
76+
* Requires {@link ngResource `ngResource`} module to be installed.
77+
*
6078
*/
6179

6280
/**
@@ -402,6 +420,52 @@ angular.module('ngResource', ['ng']).
402420
var PROTOCOL_AND_DOMAIN_REGEX = /^https?:\/\/[^\/]*/;
403421
var provider = this;
404422

423+
/**
424+
* @ngdoc property
425+
* @name $resourceProvider#defaults
426+
* @description
427+
* A configuration object for `$resource` instances.
428+
*
429+
* Properties of this object are initialized with a set of values that satisfies a wide range of use cases.
430+
* User can also choose to override these properties in application configuration phase.
431+
*
432+
* Property `stripTrailingSlashes`, default to true, strips trailing slashes from
433+
* calculated URLs.
434+
*
435+
* Property `actions` is an object that sets up high level methods/aliases on `$resource` object
436+
* based on standard HTTP methods. Users can supply an "actions" object with method aliases that
437+
* comply with alternative conventions.
438+
*
439+
* To add your own set of configurations, set it up like so:
440+
* ```
441+
* angular.module('myApp').config(['resourceProvider', function ($resourceProvider){
442+
*
443+
* // Provide your own set of actions on $resource factory.
444+
* // The following comments are Angular's default actions, which are being
445+
* // replaced by an object that includes a PUT method as shown.
446+
* // { 'get': {method:'GET'},
447+
* // 'save': {method:'POST'},
448+
* // 'query': {method:'GET', isArray:true},
449+
* // 'remove': {method:'DELETE'},
450+
* // 'delete': {method:'DELETE'} };
451+
*
452+
* $resourceProvider.defaults.actions = {
453+
* create:{method: 'POST'},
454+
* save: {method: 'POST'},
455+
* update:{method: 'PUT'},
456+
* get: {method: 'GET'},
457+
* query: {method: 'GET', isArray:true},
458+
* remove: {method: 'DELETE'},
459+
* delete: {method: 'DELETE'}
460+
* };
461+
*
462+
* // Don't strip trailing slashes from calculated URLs.
463+
* // Consult your application server's configuration to work in concert with this setting.
464+
* $resourceProvider.defaults.stripTrailingSlashes = false;
465+
* }]);
466+
* ```
467+
*
468+
*/
405469
this.defaults = {
406470
// Strip slashes by default
407471
stripTrailingSlashes: true,

0 commit comments

Comments
 (0)