Hierarchy (view full)

Constructors

Properties

$$absUrl: string

An absolute URL is the full URL, including protocol (http/https ), the optional subdomain (e.g. www ), domain (example.com), and path (which includes the directory and slug).

$$hash: string

The hash string, minus the hash symbol

$$host: string
$$html5: boolean

If html5 mode is enabled

$$path: string

The pathname, beginning with "/"

$$port: number

The port, without ":"

$$protocol: HttpProtocol
$$replace: boolean

Has any change been replacing?

$$search: any
$$state: any
$$url: string
$$urlUpdatedByLocation: boolean

Helper property for scope watch changes

appBase: string
appBaseNoFile: string

Methods

  • This method is getter / setter.

    Returns the hash fragment when called without any parameters.

    Changes the hash fragment when called with a parameter and returns $location.

    // given URL http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
    let hash = $location.hash();
    // => "hashValue"

    Parameters

    • hash: string | number

      New hash fragment

    Returns string | Location

    hash

  • This method is getter only.

    Return host of current URL.

    Note: compared to the non-AngularJS version location.host which returns hostname:port, this returns the hostname portion only.

    Returns string

    host of current URL.

  • This method is getter / setter.

    Return path of current URL when called without any parameter.

    Change path when called with parameter and return $location.

    Note: Path should always begin with forward slash (/), this method will add the forward slash if it is missing.

    // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
    let path = $location.path();
    // => "/some/path"

    Parameters

    • path: string | number

      New path

    Returns any

    path if called with no parameters, or $location if called with a parameter

  • This method is getter only.

    Return port of current URL.

    // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
    let port = $location.port();
    // => 80

    Returns number

    port

  • Returns or sets the search part (as object) of current URL when called without any parameter

    Parameters

    • search: any

      New search params - string or hash object.

    • paramValue:
          | string
          | number
          | boolean
          | string[]

      If search is a string or number, then paramValue will override only a single search property.

    • Rest...args: any

    Returns any

    Search object or Location object

  • This method is getter / setter.

    Return the history state object when called without any parameter.

    Change the history state object when called with one parameter and return $location. The state object is later passed to pushState or replaceState. See https://developer.mozilla.org/en-US/docs/Web/API/History/pushState#state|History.state

    NOTE: This method is supported only in HTML5 mode and only in browsers supporting the HTML5 History API (i.e. methods pushState and replaceState). If you need to support older browsers (like IE9 or Android < 4.0), don't use this method.

    Parameters

    • state: any

      State object for pushState or replaceState

    • Rest...args: any

    Returns any

    state

  • This method is getter / setter.

    Return URL (e.g. /path?a=b#hash) when called without any parameter. Change path, search and hash, when called with parameter and return $location.

    Parameters

    • url: string

      New URL without base prefix (e.g. /path?a=b#hash)

    Returns string | Location

    url