## RequestOptions
Creates a request options object to be optionally provided when instantiating a `Request`.
This class is based on the RequestInit description in the Fetch Spec.
All values are null by default. Typical defaults can be found in the `BaseRequestOptions` class, which sub-classes RequestOptions.
```typescript
import {RequestOptions, Request, RequestMethod} from '@angular/http';
var options = new RequestOptions({
method: RequestMethod.Post,
url: 'https://google.com'
});
var req = new Request(options);
console.log('req.method:', RequestMethod[req.method]); // Post
console.log('options.url:', options.url); // https://google.com
```
### 类定义
```typescript
class Request extends Body {
constructor(requestOptions: RequestArgs)
method : RequestMethod
headers : Headers
url : string
withCredentials : boolean
responseType : ResponseContentType
detectContentType() : ContentType
detectContentTypeFromBody() : ContentType
getBody() : any
}
```
### 属性
- method : `RequestMethod` | `string`
Http method with which to execute a `Request`. Acceptable methods are defined in the `RequestMethod` enum.
- headers : `Headers`
- body : `any` Body to be used when creating a `Request`
- url : `string` Url with which to perform a `Request`
- search : `URLSearchParams` Search parameters to be included in a `Request`
- withCredentials : `boolean` Enable use credentials
- responseType : `ResponseContentType` Buffer to store the response
- merge(options?: `RequestOptionsArgs`) : `RequestOptions`
Creates a copy of the RequestOptions 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.
Note that headers and search will override existing values completely if present in the options object. If these values should be merged, it should be done prior to calling merge on the RequestOptions instance.
```typescript
import {RequestOptions, Request, RequestMethod} from '@angular/http';
var options = new RequestOptions({
method: RequestMethod.Post
});
var req = new Request(options.merge({
url: 'https://google.com'
}));
console.log('req.method:', RequestMethod[req.method]); // Post
console.log('options.url:', options.url); // null
console.log('req.url:', req.url); // https://google.com
```
- 说明
- angular 1.x
- ngModelController
- ngOptions
- ngModelOptions
- lifecycle
- directive
- angular 2
- @angular/forms
- 类
- AbstractControl
- AbstractControlDirective
- AbstractFormGroupDirective
- FormControl
- FormArray
- FormBuilder
- FormGroup
- NgControl
- 接口
- controlValueAccessor
- 指令
- DefaultValueAccessor
- Angular 2 生命周期
- OnInit
- DoCheck
- @angular/router
- 配置
- Routes
- 指令
- RouterOutlet
- RouterLink
- 接口
- ActivatedRoute
- UrlTree
- NavigationExtras
- ActivatedRouteSnapshot
- RouterStateSnapshot
- 类
- UrlSegment
- UrlSegmentGroup
- UrlSerializer
- DefaultUrlSerializer
- Router
- bug记得
- @angular/http
- 类
- Http
- Body
- Response
- ResponseOptions
- Header
- Request
- RequestOptions
- URLSearchParams
- @angular/core
- decorator
- Component-decorator
- animation
- DI
- linker
- TemplateRef
- ElementRef
- EmbeddedViewRef
- ViewRef
- ViewContainerRef
- Query
- ComponentFactory
- ComponentRef
- Renderer
- change_detection
- KeyValueDiffers
- IterableDiffers
- ChangeDetectorRef
- ChangeDetectionStrategy
- Zone
- ngZone
- @angular/common
- 指令
- NgTemplateOutlet
- QueryList
- bootstrap4
- card
- form
- 重点关注博客
- 学习过的文章
- 笔记
- Angular 2 双向绑定
- 将字符串解析成DOM
- rx相关
- operators
- combineLatest
- combineAll
- concat(All, Map, *MapTo)
- 背压(backpressure)
- js事件keycode对应表
- 装饰器
- 有用的代码摘录
- 日期操作
- 数量操作
- 字符操作
- rxjs问题
- 小示例
- h5面试准备
- react
- 开发遇到的问题