URLSearchParams

Map-like representation of url search parameters, based on URLSearchParams in the url living standard, with several extensions for merging URLSearchParams objects:

  • setAll()
  • appendAll()
  • replaceAll()

查看"说明"...

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

      
      class URLSearchParams {
  constructor(rawParams: string = '', queryEncoder: QueryEncoder = new QueryEncoder())
  paramsMap: Map<string, string[]>
  rawParams: string
  clone(): URLSearchParams
  has(param: string): boolean
  get(param: string): string | null
  getAll(param: string): string[]
  set(param: string, val: string)
  setAll(searchParams: URLSearchParams)
  append(param: string, val: string): void
  appendAll(searchParams: URLSearchParams)
  replaceAll(searchParams: URLSearchParams)
  toString(): string
  delete(param: string): void
}
    

说明

This class accepts an optional second parameter of $QueryEncoder, which is used to serialize parameters before making a request. By default, QueryEncoder encodes keys and values of parameters using encodeURIComponent, and then un-encodes certain characters that are allowed to be part of the query according to IETF RFC 3986: https://tools.ietf.org/html/rfc3986.

These are the characters that are not encoded: ! $ \' ( ) * + , ; A 9 - . _ ~ ? /

If the set of allowed query characters is not acceptable for a particular backend, QueryEncoder can be subclassed and provided as the 2nd argument to URLSearchParams.

import {URLSearchParams, QueryEncoder} from '@angular/http'; class MyQueryEncoder extends QueryEncoder { encodeKey(k: string): string { return myEncodingFunction(k); } encodeValue(v: string): string { return myEncodingFunction(v); } } let params = new URLSearchParams('', new MyQueryEncoder());
      
      
  1. import {URLSearchParams, QueryEncoder} from '@angular/http';
  2. class MyQueryEncoder extends QueryEncoder {
  3. encodeKey(k: string): string {
  4. return myEncodingFunction(k);
  5. }
  6.  
  7. encodeValue(v: string): string {
  8. return myEncodingFunction(v);
  9. }
  10. }
  11.  
  12. let params = new URLSearchParams('', new MyQueryEncoder());

构造函数

constructor(rawParams: string = '', queryEncoder: QueryEncoder = new QueryEncoder())
      
      constructor(rawParams: string = '', queryEncoder: QueryEncoder = new QueryEncoder())
    
参数
rawParams string

可选. 默认值是 ''.

queryEncoder QueryEncoder

可选. 默认值是 new QueryEncoder().

属性

属性说明
paramsMap: Map<string, string[]>
rawParams: string 声明于构造函数中

方法

      
      clone(): URLSearchParams
    
参数

没有参数。

返回值

URLSearchParams

has(param: string): boolean
      
      has(param: string): boolean
    
参数
param string
返回值

boolean

get(param: string): string | null
      
      get(param: string): string | null
    
参数
param string
返回值

string | null

getAll(param: string): string[]
      
      getAll(param: string): string[]
    
参数
param string
返回值

string[]

set(param: string, val: string)
      
      set(param: string, val: string)
    
参数
param string
val string
setAll(searchParams: URLSearchParams)
      
      setAll(searchParams: URLSearchParams)
    
参数
searchParams URLSearchParams
append(param: string, val: string): void
      
      append(param: string, val: string): void
    
参数
param string
val string
返回值

void

appendAll(searchParams: URLSearchParams)
      
      appendAll(searchParams: URLSearchParams)
    
参数
searchParams URLSearchParams
replaceAll(searchParams: URLSearchParams)
      
      replaceAll(searchParams: URLSearchParams)
    
参数
searchParams URLSearchParams
toString(): string
      
      toString(): string
    
参数

没有参数。

返回值

string

delete(param: string): void
      
      delete(param: string): void
    
参数
param string
返回值

void