Help Angular by taking a 1 minute survey!Go to surveyHome

BaseResponseOptions

Subclass of ResponseOptions, with default values.

See more...

Deprecated: see https://angular.io/guide/http

      
      class BaseResponseOptions extends ResponseOptions {

  // inherited from http/ResponseOptions
  constructor(opts: ResponseOptionsArgs = {})
  body: string | Object | ArrayBuffer | Blob | null
  status: number | null
  headers: Headers | null
  url: string | null
  merge(options?: ResponseOptionsArgs): ResponseOptions
}
    

Description

Default values:

  • status: 200
  • headers: empty Headers object

This class could be extended and bound to the ResponseOptions class when configuring an Injector, in order to override the default options used by Http to create Responses.

Usage notes

Example

import {provide} from '@angular/core'; import {bootstrap} from '@angular/platform-browser/browser'; import {HTTP_PROVIDERS, Headers, Http, BaseResponseOptions, ResponseOptions} from '@angular/http'; import {App} from './myapp'; class MyOptions extends BaseResponseOptions { headers:Headers = new Headers({network: 'github'}); } bootstrap(App, [HTTP_PROVIDERS, {provide: ResponseOptions, useClass: MyOptions}]);
      
      import {provide} from '@angular/core';
import {bootstrap} from '@angular/platform-browser/browser';
import {HTTP_PROVIDERS, Headers, Http, BaseResponseOptions, ResponseOptions} from
'@angular/http';
import {App} from './myapp';

class MyOptions extends BaseResponseOptions {
  headers:Headers = new Headers({network: 'github'});
}

bootstrap(App, [HTTP_PROVIDERS, {provide: ResponseOptions, useClass: MyOptions}]);
    

The options could also be extended when manually creating a Response object.

Example

import {BaseResponseOptions, Response} from '@angular/http'; var options = new BaseResponseOptions(); var res = new Response(options.merge({ body: 'Angular', headers: new Headers({framework: 'angular'}) })); console.log('res.headers.get("framework"):', res.headers.get('framework')); // angular console.log('res.text():', res.text()); // Angular;
      
      import {BaseResponseOptions, Response} from '@angular/http';

var options = new BaseResponseOptions();
var res = new Response(options.merge({
  body: 'Angular',
  headers: new Headers({framework: 'angular'})
}));
console.log('res.headers.get("framework"):', res.headers.get('framework')); // angular
console.log('res.text():', res.text()); // Angular;