Skip to content

Commit 618e3f2

Browse files
committed
docs($resourceProvider): improve wording and formatting
Closes angular#11910
1 parent 140820f commit 618e3f2

File tree

1 file changed

+55
-40
lines changed

1 file changed

+55
-40
lines changed

src/ngResource/resource.js

+55-40
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ function shallowClearAndCopy(src, dst) {
5656
*
5757
* <div doc-module-components="ngResource"></div>
5858
*
59-
* See {@link ngResource.$resource `$resource`} for usage.
60-
*
61-
* See {@link ngResource.$resourceProvider `$resourceProvider`} for usage.
59+
* See {@link ngResource.$resourceProvider} and {@link ngResource.$resource} for usage.
6260
*/
6361

6462
/**
@@ -67,13 +65,11 @@ function shallowClearAndCopy(src, dst) {
6765
*
6866
* @description
6967
*
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`.
68+
* Use `$resourceProvider` to change the default behavior of the {@link ngResource.$resource}
69+
* service.
7470
*
7571
* ## Dependencies
76-
* Requires {@link ngResource `ngResource`} module to be installed.
72+
* Requires the {@link ngResource } module to be installed.
7773
*
7874
*/
7975

@@ -424,45 +420,64 @@ angular.module('ngResource', ['ng']).
424420
* @ngdoc property
425421
* @name $resourceProvider#defaults
426422
* @description
427-
* A configuration object for `$resource` instances.
423+
* Object containing default options used when creating `$resource` instances.
428424
*
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.
425+
* The default values satisfy a wide range of usecases, but you may choose to overwrite any of
426+
* them to further customize your instances. The available properties are:
431427
*
432-
* Property `stripTrailingSlashes`, default to true, strips trailing slashes from
433-
* calculated URLs.
428+
* - **stripTrailingSlashes** – `{boolean}` – If true, then the trailing slashes from any
429+
* calculated URL will be stripped.<br />
430+
* (Defaults to true.)
431+
* - **cancellable** – `{boolean}` – If true, the request made by a "non-instance" call will be
432+
* cancelled (if not already completed) by calling `$cancelRequest()` on the call's return
433+
* value. For more details, see {@link ngResource.$resource}. This can be overwritten per
434+
* resource class or action.<br />
435+
* (Defaults to false.)
436+
* - **actions** - `{Object.<Object>}` - A hash with default actions declarations. Actions are
437+
* high-level methods corresponding to RESTful actions/methods on resources. An action may
438+
* specify what HTTP method to use, what URL to hit, if the return value will be a single
439+
* object or a collection (array) of objects etc. For more details, see
440+
* {@link ngResource.$resource}. The actions can also be enhanced or overwritten per resource
441+
* class.<br />
442+
* The default actions are:
443+
* ```js
444+
* {
445+
* get: {method: 'GET'},
446+
* save: {method: 'POST'},
447+
* query: {method: 'GET', isArray: true},
448+
* remove: {method: 'DELETE'},
449+
* delete: {method: 'DELETE'}
450+
* }
451+
* ```
434452
*
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.
453+
* #### Example
438454
*
439-
* To add your own set of configurations, set it up like so:
440-
* ```
441-
* angular.module('myApp').config(['resourceProvider', function ($resourceProvider){
455+
* For example, you can specify a new `update` action that uses the `PUT` HTTP verb:
442456
*
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'} };
457+
* ```js
458+
* angular.
459+
* module('myApp').
460+
* config(['resourceProvider', function ($resourceProvider) {
461+
* $resourceProvider.defaults.actions.update = {
462+
* method: 'PUT'
463+
* };
464+
* });
465+
* ```
451466
*
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-
* };
467+
* Or you can even overwrite the whole `actions` list and specify your own:
461468
*
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-
* }]);
469+
* ```js
470+
* angular.
471+
* module('myApp').
472+
* config(['resourceProvider', function ($resourceProvider) {
473+
* $resourceProvider.defaults.actions = {
474+
* create: {method: 'POST'}
475+
* get: {method: 'GET'},
476+
* getAll: {method: 'GET', isArray:true},
477+
* update: {method: 'PUT'},
478+
* delete: {method: 'DELETE'}
479+
* };
480+
* });
466481
* ```
467482
*
468483
*/

0 commit comments

Comments
 (0)