-
Notifications
You must be signed in to change notification settings - Fork 27.4k
docs($resourceProvider): provide info and example for configuring $re… #11910
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,24 @@ function shallowClearAndCopy(src, dst) { | |
* <div doc-module-components="ngResource"></div> | ||
* | ||
* See {@link ngResource.$resource `$resource`} for usage. | ||
* | ||
* See {@link ngResource.$resourceProvider `$resourceProvider`} for usage. | ||
*/ | ||
|
||
/** | ||
* @ngdoc provider | ||
* @name $resourceProvider | ||
* | ||
* @description | ||
* | ||
* Use for configuring {@link ngResource.$resource `$resource`} in module configuration phase. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather change it to something like:
(You don't have to mention the configuration phase. It's not specific to this provider and we don't want to mention such stuff in every provider's documentation.) |
||
* | ||
* ## Example | ||
* See {@link ngResource.$resourceProvider#defaults `Properties`} for configuring `ngResource`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This Example section is redundant imo. |
||
* | ||
* ## Dependencies | ||
* Requires {@link ngResource `ngResource`} module to be installed. | ||
* | ||
*/ | ||
|
||
/** | ||
|
@@ -349,6 +367,52 @@ angular.module('ngResource', ['ng']). | |
provider('$resource', function() { | ||
var provider = this; | ||
|
||
/** | ||
* @ngdoc property | ||
* @name $resourceProvider#defaults | ||
* @description | ||
* A configuration object for `$resource` instances. | ||
* | ||
* Properties of this object are initialized with a set of values that satisfies a wide range of use cases. | ||
* User can also choose to override these properties in application configuration phase. | ||
* | ||
* Property `stripTrailingSlashes`, default to true, strips trailing slashes from | ||
* calculated URLs. | ||
* | ||
* Property `actions` is an object that sets up high level methods/aliases on `$resource` object | ||
* based on standard HTTP methods. Users can supply an "actions" object with method aliases that | ||
* comply with alternative conventions. | ||
* | ||
* To add your own set of configurations, set it up like so: | ||
* ``` | ||
* angular.module('myApp').config(['resourceProvider', function ($resourceProvider){ | ||
* | ||
* // Provide your own set of actions on $resource factory. | ||
* // The following comments are Angular's default actions, which are being | ||
* // replaced by an object that includes a PUT method as shown. | ||
* // { 'get': {method:'GET'}, | ||
* // 'save': {method:'POST'}, | ||
* // 'query': {method:'GET', isArray:true}, | ||
* // 'remove': {method:'DELETE'}, | ||
* // 'delete': {method:'DELETE'} }; | ||
* | ||
* $resourceProvider.defaults.actions = { | ||
* create:{method: 'POST'}, | ||
* save: {method: 'POST'}, | ||
* update:{method: 'PUT'}, | ||
* get: {method: 'GET'}, | ||
* query: {method: 'GET', isArray:true}, | ||
* remove: {method: 'DELETE'}, | ||
* delete: {method: 'DELETE'} | ||
* }; | ||
* | ||
* // Don't strip trailing slashes from calculated URLs. | ||
* // Consult your application server's configuration to work in concert with this setting. | ||
* $resourceProvider.defaults.stripTrailingSlashes = false; | ||
* }]); | ||
* ``` | ||
* | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you bring this more inline with how |
||
this.defaults = { | ||
// Strip slashes by default | ||
stripTrailingSlashes: true, | ||
|
@@ -363,6 +427,22 @@ angular.module('ngResource', ['ng']). | |
} | ||
}; | ||
|
||
/** | ||
* @ngdoc method | ||
* @name $resourceProvider#$get | ||
* @description Method used by angular DI system to create a `$resourceProvider` instance. | ||
* | ||
* User applications shouldn't need to call this method directly. | ||
* This shows the fact that {@link ngResource.$resource $resource} | ||
* is a high level service built by leveraging {@link ng.$http $http} service. | ||
* | ||
* @param {Object} $http An instance of {@link ng.$http $http} service. | ||
* | ||
* @param {Object} $q An instance {@link ng.$q $q}, Angular's implementation of deferred API. | ||
* | ||
* | ||
* @returns {Function} A factory function, when invoked, returns a $resource object. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
this.$get = ['$http', '$q', function($http, $q) { | ||
|
||
var noop = angular.noop, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge these two lines into: