$browser
(service in module ng
)
This object has two goals:
For tests we provide mock implementation
of the $browser
service, which can be used for convenient testing of the application without the interaction with
the real browser apis.
Adds a function to the list of functions that poller periodically executes, and starts polling if not started yet.
fn – {function()} –
Poll function to add
{function()}
– the added function
Executes a fn asynchroniously via setTimeout(fn, delay)
.
Unlike when calling setTimeout
directly, in test this function is mocked and instead of using
setTimeout
in tests, the fns are queued in an array, which can be programmatically flushed
via $browser.defer.flush()
.
fn – {function()} –
A function, who's execution should be defered.
delay(optional=0) – {number=} –
of milliseconds to defer the function execution.
{*}
– DeferId that can be used to cancel the task via $browser.defer.cancel()
.
Register callback function that will be called, when url changes.
It's only called when the url is changed by outside of angular: - user types different url into address bar - user clicks on history (forward/back) button - user clicks on a link
It's not called when url is changed by $browser.url() method
The listener gets called with new url as parameter.
NOTE: this api is intended for use only by the $location service. Please use the
$location service
to monitor url changes in angular apps.
listener – {function(string)} –
Listener function to be called when url changes.
GETTER: Without any argument, this method just returns current value of location.href.
SETTER: With at least one argument, this method sets url to new value. If html5 history api supported, pushState/replaceState is used, otherwise location.href/location.replace is used. Returns its own instance to allow chaining
NOTE: this api is intended for use only by the $location service. Please use the
$location service
to change url.
url – {string} –
New url (when used as setter)
replace(optional) – {boolean=} –
Should new url replace current history record ?