URLSearchParams

class deprecated

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 more...

Deprecated: 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
}

Description

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());

Constructor

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

Parameters

rawParams

Type: string.

Optional. Default is ''.

queryEncoder

Type: QueryEncoder.

Optional. Default is new QueryEncoder().

Properties

Property Description
paramsMap: Map<string, string[]>
rawParams: string Declared in constructor.

Methods

clone(): URLSearchParams

Parameters

There are no parameters.

Returns

URLSearchParams

has(param: string): boolean

Parameters

param

Type: string.

Returns

boolean

get(param: string): string | null

Parameters

param

Type: string.

Returns

string | null

getAll(param: string): string[]

Parameters

param

Type: string.

Returns

string[]

set(param: string, val: string)

Parameters

param

Type: string.

val

Type: string.

setAll(searchParams: URLSearchParams)

Parameters

searchParams

Type: URLSearchParams.

append(param: string, val: string): void

Parameters

param

Type: string.

val

Type: string.

Returns

void

appendAll(searchParams: URLSearchParams)

Parameters

searchParams

Type: URLSearchParams.

replaceAll(searchParams: URLSearchParams)

Parameters

searchParams

Type: URLSearchParams.

toString(): string

Parameters

There are no parameters.

Returns

string

delete(param: string): void

Parameters

param

Type: string.

Returns

void

© 2010–2019 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v6.angular.io/api/http/URLSearchParams