diff options
| author | Igor Minar | 2012-04-10 23:20:53 -0700 | 
|---|---|---|
| committer | Igor Minar | 2012-04-11 17:29:16 -0700 | 
| commit | dceafd32ee140c8af5c7a0ca6cb808395fffeed3 (patch) | |
| tree | a594376801fa05233c39a58a7b7976d2a3b3fc20 /src | |
| parent | 0a5050eb3c1f1ed84134f23a44b97a7261114060 (diff) | |
| download | angular.js-dceafd32ee140c8af5c7a0ca6cb808395fffeed3.tar.bz2 | |
feat($http): expose the defaults config as $http.defaults
Often it is impossible to set the http defaults during the config phase,
because the config info is not available at this time.
A good example is authentication - often the app needs to bootstrap,
allow user to enter credentials and only then it gains access to
session token which then should be sent to the server with every request.
Without having the ability to set the defaults at runtime, the developer
either has to resort to hacks, or has to set the session token header
with every request made by the app.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ng/http.js | 16 | 
1 files changed, 16 insertions, 0 deletions
| diff --git a/src/ng/http.js b/src/ng/http.js index 3942c5c7..0c16e2d0 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -223,6 +223,9 @@ function $HttpProvider() {       * with name equal to the lower-cased http method name, e.g.       * `$httpProvider.defaults.headers.get['My-Header']='value'`.       * +     * Additionally, the defaults can be set at runtime via the `$http.defaults` object in a similar +     * fassion as described above. +     *       *       * # Transforming Requests and Responses       * @@ -604,6 +607,19 @@ function $HttpProvider() {       */      createShortMethodsWithData('post', 'put'); +        /** +         * @ngdoc property +         * @name angular.module.ng.$http#defaults +         * @propertyOf angular.module.ng.$http +         * +         * @description +         * Runtime equivalent of the `$httpProvider.defaults` property. Allows configuration of +         * default headers as well as request and response transformations. +         * +         * See "Setting HTTP Headers" and "Transforming Requests and Responses" sections above. +         */ +    $http.defaults = $config; +      return $http; | 
