TestRequest

A mock requests that was received and is ready to be answered.

查看"说明"...

      
      class TestRequest {
  constructor(request: HttpRequest<any>, observer: Observer<HttpEvent<any>>)
  cancelled: boolean
  request: HttpRequest<any>
  flush(body: string | number | Object | ArrayBuffer | Blob | (string | number | Object)[], opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void
  error(error: ErrorEvent, opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void
  event(event: HttpEvent<any>): void
}
    

说明

This interface allows access to the underlying HttpRequest, and allows responding with HttpEvents or HttpErrorResponses.

构造函数

constructor(request: HttpRequest<any>, observer: Observer<HttpEvent<any>>)
      
      constructor(request: HttpRequest<any>, observer: Observer<HttpEvent<any>>)
    
参数
request HttpRequest
observer Observer>

属性

属性说明
cancelled: boolean 只读

Whether the request was cancelled after it was sent.

request: HttpRequest<any> 声明于构造函数中

方法

Resolve the request by returning a body plus additional HTTP information (such as response headers) if provided.

flush(body: string | number | Object | ArrayBuffer | Blob | (string | number | Object)[], opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void
      
      flush(body: string | number | Object | ArrayBuffer | Blob | (string | number | Object)[], opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void
    
参数
body string | number | Object | ArrayBuffer | Blob | (string | number | Object)[]
opts object

可选. 默认值是 {}.

返回值

void

Both successful and unsuccessful responses can be delivered via flush().

Resolve the request by returning an ErrorEvent (e.g. simulating a network failure).

error(error: ErrorEvent, opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void
      
      error(error: ErrorEvent, opts: { headers?: HttpHeaders | { [name: string]: string | string[]; }; status?: number; statusText?: string; } = {}): void
    
参数
error ErrorEvent
opts object

可选. 默认值是 {}.

返回值

void

Deliver an arbitrary HttpEvent (such as a progress event) on the response stream for this request.

event(event: HttpEvent<any>): void
      
      event(event: HttpEvent<any>): void
    
参数
event HttpEvent
返回值

void