$locationShim
$locationShim
class
Location service that provides a drop-in replacement for the $location service provided in AngularJS.
class $locationShim {
constructor($injector: any, location: Location, platformLocation: PlatformLocation, urlCodec: UrlCodec, locationStrategy: LocationStrategy)
onChange(fn: (url: string, state: unknown, oldUrl: string, oldState: unknown) => void, err: (e: Error) => void = (e: Error) => { })
$$parse(url: string)
$$parseLinkUrl(url: string, relHref?: string): boolean
absUrl(): string
url(url?: string): string | this
protocol(): string
host(): string
port(): number | null
path(path?: string | number): string | this
search(search?: string | number | { [key: string]: unknown; }, paramValue?: string | number | boolean | string[]): {...}
hash(hash?: string | number): string | this
replace(): this
state(state?: unknown): unknown | this
}
See also
Constructor
constructor($injector: any, location: Location, platformLocation: PlatformLocation, urlCodec: UrlCodec, locationStrategy: LocationStrategy)Parameters
|
Methods
onChange() | ||||||
---|---|---|---|---|---|---|
Registers listeners for URL changes. This API is used to catch updates performed by the AngularJS framework. These changes are a subset of the $locationChangeStart and $locationChangeSuccess events which fire when AngularJS updates its internally-referenced version of the browser URL.
| ||||||
onChange(fn: (url: string, state: unknown, oldUrl: string, oldState: unknown) => void, err: (e: Error) => void = (e: Error) => { })Parameters
| ||||||
It's possible for $locationChange events to happen, but for the browser URL (window.location) to remain unchanged. This onChange callback will fire only when AngularJS actually updates the browser URL (window.location).
|
$$parse() | |||
---|---|---|---|
Parses the provided URL, and sets the current URL to the parsed result. | |||
$$parse(url: string)Parameters
|
$$parseLinkUrl() | ||||||
---|---|---|---|---|---|---|
Parses the provided URL and its relative URL. | ||||||
$$parseLinkUrl(url: string, relHref?: string): booleanParameters
Returns
|
absUrl() |
---|
Retrieves the full URL representation with all segments encoded according to rules specified in RFC 3986. |
absUrl(): stringParametersThere are no parameters. Returns
|
|
url() | |||
---|---|---|---|
Retrieves the current URL, or sets a new URL. When setting a URL, changes the path, search, and hash, and returns a reference to its own instance.
url(): stringParametersThere are no parameters. Returns
| |||
url(url: string): thisParameters
Returns
| |||
|
protocol() |
---|
Retrieves the protocol of the current URL. |
protocol(): stringParametersThere are no parameters. Returns
|
|
host() |
---|
Retrieves the protocol of the current URL. |
host(): stringParametersThere are no parameters. Returns
|
In contrast to the non-AngularJS version
|
port() |
---|
Retrieves the port of the current URL. |
port(): number | nullParametersThere are no parameters. Returns
|
|
path() | |||
---|---|---|---|
Retrieves the path of the current URL, or changes the path and returns a reference to its own instance.
path(): stringParametersThere are no parameters. Returns
| |||
path(path: string | number): thisParameters
Returns
| |||
Paths should always begin with forward slash (/). This method adds the forward slash if it is missing.
|
search() | |||||||||
---|---|---|---|---|---|---|---|---|---|
3 overloads...Show All Hide All Overload #1Retrieves a map of the search parameters of the current URL, or changes a search part and returns a reference to its own instance.
=== search(): { [key: string]: unknown; } === ParametersThere are no parameters. Returns`{ }
Overload #2search(search: string | number | { [key: string]: unknown; }): thisParameters
Returns
Overload #3search(search: string | number | { [key: string]: unknown; }, paramValue: string | number | boolean | string[]): thisParameters
Returns
| |||||||||
|
hash() | |||
---|---|---|---|
Retrieves the current hash fragment, or changes the hash fragment and returns a reference to its own instance.
hash(): stringParametersThere are no parameters. Returns
| |||
hash(hash: string | number): thisParameters
Returns
| |||
|
replace() |
---|
Changes to $location during the current $digest will replace the current history record, instead of adding a new one.
|
replace(): thisParametersThere are no parameters. Returns
|
state() | |||
---|---|---|---|
Retrieves the history state object when called without any parameter.
state(): unknownParametersThere are no parameters. Returns
| |||
state(state: unknown): thisParameters
Returns
| |||
Change the history state object when called with one parameter and return This method is supported only in HTML5 mode and only in browsers supporting the HTML5 History API methods such as |
© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v10.angular.io/api/common/upgrade/$locationShim