ResponseOptions

Creates a response options object to be optionally provided when instantiating a Response.

查看"说明"...

已弃用: see https://angular.io/guide/http

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

说明

This class is based on the ResponseInit description in the Fetch Spec.

All values are null by default. Typical defaults can be found in the BaseResponseOptionsclass, which sub-classes ResponseOptions.

This class may be used in tests to build Responses for mock responses (see MockBackend).

构造函数

constructor(opts: ResponseOptionsArgs = {})
      
      constructor(opts: ResponseOptionsArgs = {})
    
参数
opts ResponseOptionsArgs

可选. 默认值是 {}.

属性

属性说明
body: string | Object | ArrayBuffer | Blob | null

String, Object, ArrayBuffer or Blob representing the body of the Response.

status: number | null

Http status code associated with the response.

headers: Headers | null

Response headers

url: string | null

方法

Creates a copy of the ResponseOptions instance, using the optional input as values to override existing values. This method will not change the values of the instance on which it is being called.

      
      merge(options?: ResponseOptionsArgs): ResponseOptions
    
参数
options ResponseOptionsArgs

可选. 默认值是 undefined.

返回值

ResponseOptions

This may be useful when sharing a base ResponseOptions object inside tests, where certain properties may change from test to test.

使用说明

Example
import {ResponseOptions, Response} from '@angular/http'; var options = new ResponseOptions({ body: {name: 'Jeff'} }); var res = new Response(options.merge({ url: 'https://google.com' })); console.log('options.url:', options.url); // null console.log('res.json():', res.json()); // Object {name: "Jeff"} console.log('res.url:', res.url); // https://google.com
      
      import {ResponseOptions, Response} from '@angular/http';

var options = new ResponseOptions({
  body: {name: 'Jeff'}
});
var res = new Response(options.merge({
  url: 'https://google.com'
}));
console.log('options.url:', options.url); // null
console.log('res.json():', res.json()); // Object {name: "Jeff"}
console.log('res.url:', res.url); // https://google.com
    

使用说明

Example

import {ResponseOptions, Response} from '@angular/http'; var options = new ResponseOptions({ body: '{"name":"Jeff"}' }); var res = new Response(options); console.log('res.json():', res.json()); // Object {name: "Jeff"}
      
      import {ResponseOptions, Response} from '@angular/http';

var options = new ResponseOptions({
  body: '{"name":"Jeff"}'
});
var res = new Response(options);

console.log('res.json():', res.json()); // Object {name: "Jeff"}