Show Menu
Cheatography

Angular Js v1.3.0 Services Cheat Sheet (DRAFT) by

Angular Js v1.3.0 Services

This is a draft cheat sheet. It is a work in progress and is not finished yet.

animate

The $animate service provides rudime­ntary DOM manipu­lation functions to insert, remove and move elements within the DOM, as well as adding and removing classes. This service is the core service used by the ngAnimate $animator service which provides high-level animation hooks for CSS and JavaSc­ript.
Methods
enter(­ele­ment, parent, after, [done]);
Inserts the element into the DOM either after the after element or as the first child within the parent element. Once complete, the done() callback will be fired (if provided).
element, DOMElement: the element which will be inserted into the DOM
parent, DOMElement: the parent element which will append the element as a child (if the after element is not present)
after, DOMElement: the sibling element which will append the element after itself
done(optio­nal), Function=: callback function that will be called after the element has been inserted into the DOM
move(e­lement, parent, after, [done]);
Moves the position of the provided element within the DOM to be placed either after the after element or inside of the parent element. Once complete, the done() callback will be fired (if provided).
element, DOMElement: the element which will be moved around within the DOM
parent. DOMElement: the parent element where the element will be inserted into (if the after element is not present)
after, DOMElement: the sibling element where the element will be positioned next to
done(optio­nal), Function=: the callback function (if provided) that will be fired after the element has been moved to its new position
addCla­ss(­ele­ment, className, [done]);
Adds the provided className CSS class value to the provided element. Once complete, the done() callback will be fired (if provided).
element, DOMElement: the element which will have the className value added to it
className, string: the CSS class which will be added to the element
done(optio­nal), Function=: the callback function (if provided) that will be fired after the className value has been added to the element
remove­Cla­ss(­ele­ment, className, [done]);
Removes the provided className CSS class value from the provided element. Once complete, the done() callback will be fired (if provided).
element, DOMElement: the element which will have the className value removed from it
className, string: the CSS class which will be removed from the element
done(optio­nal), Function=: the callback function (if provided) that will be fired after the className value has been removed from the element
setCla­ss(­ele­ment, add, remove, [done]);
Adds and/or removes the given CSS classes to and from the element. Once complete, the done() callback will be fired (if provided).
element, DOMElement: the element which will have its CSS classes changed removed from it
add, string: the CSS classes which will be added to the element
remove, string: the CSS class which will be removed from the element
done(optio­nal), Function=: the callback function (if provided) that will be fired after the CSS classes have been set on the element

cacheF­actory

Factory that constructs Cache objects and gives access to them.
Usage:
$cache­Fac­tor­y(c­acheId, [optio­ns]);
Arguments:
cacheId, string: Name or id of the newly created cache.
options(optio­nal), object: Options object that specifies the cache behavior. Proper­ties:
{number=} capacity — turns the cache into LRU cache.
Returns:
object: Newly created cache object with the following set of methods:
{object} info() — Returns id, size, and options of cache.
{{}} put({s­tring} key, {} value) — Puts a new key-value pair into the cache and returns it.
{{}} get({s­tring} key)* — Returns cached value for key or undefined for cache miss.
{void} remove­({s­tring} key) — Removes a key-value pair from the cache.
{void} remove­All() — Removes all cached values.
{void} destroy() — Removes references to this cache from $cache­Fac­tory.
Methods:
info(); — Get inform­ation about all the caches that have been created
Returns:
Object — key-value map of cacheId to the result of calling cache#info
get(ca­cheId); — Get access to a cache object by the cacheId used when it was created.
Parame­ters:
cacheId,string — Name or id of a cache to access.
Returns:
object: Cache object identified by the cacheId or undefined if no such cache.

compile

Compiles an HTML string or DOM into a template and produces a template function, which can then be used to link scope and the template together.
Usage
$compi­le(­ele­ment, transc­lude, maxPri­ority);
Arguments
element, (string | DOMEle­ment): Element or HTML string to compile into a template function.
transclude, functi­on(­ang­ula­r.S­cope, cloneA­tta­chFn=):
function available to direct­ives.
maxPri­ority, number: only apply directives lower than given priority (Only effects the root elemen­t(s), not their children)
Returns
functi­on(­scope, cloneA­tta­chFn=): a link function which is used to bind template (a DOM elemen­t/tree) to a scope. Where:
scope - A Scope to bind to.
cloneA­ttachFn - If cloneA­ttachFn is provided, then the link function will clone the template and call the cloneA­ttachFn function allowing the caller to attach the cloned elements to the DOM document at the approp­riate place. The cloneA­ttachFn is called as: cloneA­tta­chF­n(c­lon­edE­lement, scope) where:
cloned­Element - is a clone of the original element passed into the compiler.
scope - is the current scope with which the linking function is working with.
Calling the linking function returns the element of the template. It is either the original element passed in, or the clone of the element if the cloneA­ttachFn is provided.

interp­olate

Compiles a string with markup into an interp­olation function. This service is used by the HTML $compile service for data binding.
Usage
$inter­pol­ate­(text, [mustH­ave­Exp­res­sion], [trust­edC­ont­ext], [allOr­Not­hing]);
text - {string} - The text with markup to interp­olate.
mustHa­veE­xpr­ession (optional) - {boolean} - if set to true then the interp­olation string must have embedded expression in order to return an interp­olation function. Strings with no embedded expression will return null for the interp­olation function.
truste­dCo­ntext (optional) - {string} - when provided, the returned function passes the interp­olated result through $sce.g­etT­rus­ted­(in­ter­pol­ate­dRe­sult, truste­dCo­ntext) before returning it. Refer to the $sce service that provides Strict Contextual Escaping for details.
allOrN­othing (optional) - {boolean} - if true, then the returned function returns undefined unless all embedded expres­sions evaluate to a value other than undefined.

Returns:
functi­on(­con­text) - an interp­olation function which is used to compute the interp­olated string. The function has these parame­ters:
- context: evaluation context for all expres­sions embedded in the interp­olated text

Methods:
startS­ymb­ol(); - Symbol to denote the start of expression in the interp­olated string. Defaults to {{.
Use $inter­pol­ate­Pro­vid­er#­sta­rtS­ymbol to change the symbol.
Returns:
{string} - start symbol.

endSym­bol(); - Symbol to denote the end of expression in the interp­olated string. Defaults to }}.
Use $inter­pol­ate­Pro­vid­er#­end­Symbol to change the symbol.

parse

Converts Angular expression into a function.
Usage
$parse­(ex­pre­ssion);
Arguments:
expression - {string} - String expression to compile.
Returns:
functi­on(­con­text, locals) - a function which represents the compiled expres­sion:
context – {object} – an object against which any expres­sions embedded in the strings are evaluated against (typically a scope object).
locals – {object=} – local variables context object, useful for overriding values in context.

The returned function also has the following proper­ties:
literal – {boolean} – whether the expres­sion's top-level node is a JavaScript literal.
constant – {boolean} – whether the expression is made entirely of JavaScript constant literals.
assign – {?func­tio­n(c­ontext, value)} – if the expression is assign­able, this will be set to a function to change its value on the given context.

controller

$contr­oller service is respon­sible for instan­tiating contro­llers.
Usage
$contr­oll­er(­con­str­uctor, locals);
Arguments
constr­uctor, (funct­ion() | string): If called with a function then it's considered to be the controller constr­uctor function. Otherwise it's considered to be a string which is used to retrieve the controller constr­uctor using the following steps:
- check if a controller with given name is registered via $contr­oll­erP­rovider
- check if evaluating the string on the current scope returns a constr­uctor
- if $contr­oll­erP­rov­ide­r#a­llo­wGl­obals, check window­[co­nst­ructor] on the global window object (not recomm­ended)

except­ion­Handler

Any uncaught exception in angular expres­sions is delegated to this service. The default implem­ent­ation simply delegates to $log.error which logs it into the browser console.
Example:
angula­r.m­odu­le(­'ex­cep­tio­nOv­err­ide', []).fa­cto­ry(­'$e­xce­pti­onH­and­ler', function () {`
return function (excep­tion, cause) {
except­ion.me­ssage += (caused by "' + cause + '")';`
throw exception;
};
});
This example will override the normal action of $excep­tio­nHa­ndler, to make angular exceptions fail hard when they happen, instead of just logging to the console.

Usage
$excep­tio­nHa­ndl­er(­exc­eption, [cause]);
Arguments
exception, Error: Exception associated with the error.
cause (optio­nal), string: optional inform­ation about the context in which the error was thrown.

sce

$sce is a service that provides Strict Contextual Escaping services to AngularJS.
Usage
$sce();
Methods:
isEnab­led(); - Returns a boolean indicating if SCE is enabled.
Returns:
Boolean - true if SCE is enabled, false otherwise. If you want to set the value, you have to do it at module config time on $scePr­ovider.
parseA­s(type, expres­sion); - Converts Angular expression into a function. This is like $parse and is identical when the expression is a literal constant. Otherwise, it wraps the expression in a call to $sce.g­etT­rus­ted­(type, result)
Parame­ters:
type - {string} - The kind of SCE context in which this result will be used.
expression - {string} - String expression to compile.
Returns:
functi­on(­con­text, locals) - a function which represents the compiled expres­sion:
context – {object} – an object against which any expres­sions embedded in the strings are evaluated against (typically a scope object).
locals – {object=} – local variables context object, useful for overriding values in context.
trustA­s(type, value); - Delegates to $sceDe­leg­ate.tr­ustAs. As such, returns an object that is trusted by angular for use in specified strict contextual escaping contexts (such as ng-bin­d-html, ng-inc­lude, any src attribute interp­ola­tion, any dom event binding attribute interp­olation such as for onclick, etc.) that uses the provided value. See * $sce for enabling strict contextual escaping.
Parame­ters:
type - {string} - The kind of context in which this value is safe for use. e.g. url, resour­ce_url, html, js and css.
value - {*} - The value that that should be considered truste­d/safe.
Returns
* - A value that can be used to stand in for the provided value in places where Angular expects a $sce.t­rus­tAs() return value.
trustA­sHt­ml(­value); - Shorthand method. $sce.t­rus­tAs­Htm­l(v­alue) → $sceDe­leg­ate.tr­ust­As(­$sc­e.HTML, value)
Parame­ters:
value - * - The value to trustAs.
Returns:
* - An object that can be passed to $sce.g­etT­rus­ted­Htm­l(v­alue) to obtain the original value. (privi­leged directives only accept expres­sions that are either literal constants or are the return value of $sce.t­rus­tAs.)
trustA­sUr­l(v­alue); - Shorthand method. $sce.t­rus­tAs­Url­(value) → $sceDe­leg­ate.tr­ust­As(­$sc­e.URL, value)
Parame­ters:
value - * - The value to trustAs.
Returns:
* - An object that can be passed to $sce.g­etT­rus­ted­Url­(value) to obtain the original value. (privi­leged directives only accept expres­sions that are either literal constants or are the return value of $sce.t­rus­tAs.)
trustA­sRe­sou­rce­Url­(va­lue); - Shorthand method. $sce.t­rus­tAs­Res­our­ceU­rl(­value) → $sceDe­leg­ate.tr­ust­As(­$sc­e.R­ESO­URC­E_URL, value)
Parame­ters:
value - * - The value to trustAs.
Returns:
* - An object that can be passed to $sce.g­etT­rus­ted­Res­our­ceU­rl(­value) to obtain the original value. (privi­leged directives only accept expres­sions that are either literal constants or are the return value of $sce.t­rus­tAs.)
trustA­sJs­(va­lue); - Shorthand method. $sce.t­rus­tAs­Js(­value) → $sceDe­leg­ate.tr­ust­As(­$sc­e.JS, value)
Parame­ters:
value, * - The value to trustAs.
Returns:
* - An object that can be passed to $sce.g­etT­rus­ted­Js(­value) to obtain the original value. (privi­leged directives only accept expres­sions that are either literal constants or are the return value of $sce.t­rus­tAs.)
getTru­ste­d(type, maybeT­rus­ted); - Delegates to $sceDe­leg­ate.ge­tTr­usted. As such, takes the result of a $sce.t­rus­tAs() call and returns the originally supplied value if the queried context type is a supertype of the created type. If this condition isn't satisfied, throws an exception.
Parame­ters:
type - {string} - The kind of context in which this value is to be used.
maybeT­rusted - {*} - The result of a prior $sce.t­rustAs call.
Returns:
* - The value the was originally provided to $sce.t­rustAs if valid in this context. Otherwise, throws an exception.
getTru­ste­dHt­ml(­value); - Shorthand method. $sce.g­etT­rus­ted­Htm­l(v­alue) → $sceDe­leg­ate.ge­tTr­ust­ed(­$sc­e.HTML, value)
Parame­ters:
value - {*} - The value to pass to $sce.g­etT­rusted.
Returns:
* - The return value of $sce.g­etT­rus­ted­($s­ce.H­TML, value)
getTru­ste­dCs­s(v­alue); - Shorthand method. $sce.g­etT­rus­ted­Css­(value) → $sceDe­leg­ate.ge­tTr­ust­ed(­$sc­e.CSS, value)
Parameters
value - {*} - The value to pass to $sce.g­etT­rusted.
Returns:
* - The return value of $sce.g­etT­rus­ted­($s­ce.CSS, value)
getTru­ste­dUr­l(v­alue); - Shorthand method. $sce.g­etT­rus­ted­Url­(value) → $sceDe­leg­ate.ge­tTr­ust­ed(­$sc­e.URL, value)
Parame­ters:
value - {*} - The value to pass to $sce.g­etT­rusted.
Returns:
* - The return value of $sce.g­etT­rus­ted­($s­ce.URL, value)
getTru­ste­dRe­sou­rce­Url­(va­lue); - Shorthand method. $sce.g­etT­rus­ted­Res­our­ceU­rl(­value) → $sceDe­leg­ate.ge­tTr­ust­ed(­$sc­e.R­ESO­URC­E_URL, value)
Parame­ters:
value - {*} - The value to pass to $sceDe­leg­ate.ge­tTr­usted.
Returns:
* - The return value of $sce.g­etT­rus­ted­($s­ce.R­ES­OUR­CE_URL, value)
getTru­ste­dJs­(va­lue); - Shorthand method. $sce.g­etT­rus­ted­Js(­value) → $sceDe­leg­ate.ge­tTr­ust­ed(­$sc­e.JS, value)
Parame­ters:
value - * - The value to pass to $sce.g­etT­rusted.
Returns:
* - The return value of $sce.g­etT­rus­ted­($s­ce.JS, value)
parseA­sHt­ml(­exp­res­sion); - Shorthand method. $sce.p­ars­eAs­Htm­l(e­xpr­ession string) → $sce.p­ars­eAs­($s­ce.H­TML, value)
Parame­ters:
expression - {string} - String expression to compile.
Returns:
functi­on(­con­text, locals) - a function which represents the compiled expres­sion:
context – {object} – an object against which any expres­sions embedded in the strings are evaluated against (typically a scope object).
locals – {object=} – local variables context object, useful for overriding values in context.
parseA­sCs­s(e­xpr­ess­ion); - Shorthand method. $sce.p­ars­eAs­Css­(value) → $sce.p­ars­eAs­($s­ce.CSS, value)
Parame­ters:
expression - {string} - String expression to compile.
Returns:
functi­on(­con­text, locals) - a function which represents the compiled expres­sion:
context – {object} – an object against which any expres­sions embedded in the strings are evaluated against (typically a scope object).
locals – {object=} – local variables context object, useful for overriding values in context.
parseA­sUr­l(e­xpr­ess­ion); - Shorthand method. $sce.p­ars­eAs­Url­(value) → $sce.p­ars­eAs­($s­ce.URL, value)
Parame­ters:
expression - {string} - String expression to compile.
Returns:
functi­on(­con­text, locals) - a function which represents the compiled expres­sion:
context – {object} – an object against which any expres­sions embedded in the strings are evaluated against (typically a scope object).
locals – {object=} – local variables context object, useful for overriding values in context.
parseA­sRe­sou­rce­Url­(ex­pre­ssion); - Shorthand method. $sce.p­ars­eAs­Res­our­ceU­rl(­value) → $sce.p­ars­eAs­($s­ce.R­ES­OUR­CE_URL, value)
Parame­ters:
expression - {string} - String expression to compile.
Returns:
functi­on(­con­text, locals) - a function which represents the compiled expres­sion:
context – {object} – an object against which any expres­sions embedded in the strings are evaluated against (typically a scope object).
locals – {object=} – local variables context object, useful for overriding values in context.
parseA­sJs­(ex­pre­ssion); - Shorthand method. $sce.p­ars­eAs­Js(­value) → $sce.p­ars­eAs­($s­ce.JS, value)
Parame­ters:
expression - {string} - String expression to compile.
Returns:
functi­on(­con­text, locals) - a function which represents the compiled expres­sion:
context – {object} – an object against which any expres­sions embedded in the strings are evaluated against (typically a scope object).
locals – {object=} – local variables context object, useful for overriding values in context.

sceDel­egate

$sceDe­legate is a service that is used by the $sce service to provide Strict Contextual Escaping (SCE) services to AngularJS.
Methods:
trustA­s(type, value); - Returns an object that is trusted by angular for use in specified strict contextual escaping contexts (such as ng-bin­d-html, ng-inc­lude, any src attribute interp­ola­tion, any dom event binding attribute interp­olation such as for onclick, etc.) that uses the provided value. See $sce for enabling strict contextual escaping.
Parame­ters:
type - {string} - The kind of context in which this value is safe for use. e.g. url, resour­ceUrl, html, js and css.
value - {*} - The value that that should be considered truste­d/safe.
Returns:
* - A value that can be used to stand in for the provided value in places where Angular expects a $sce.t­rus­tAs() return value.
valueO­f(v­alue); - If the passed parameter had been returned by a prior call to $sceDe­leg­ate.tr­ustAs, returns the value that had been passed to $sceDe­leg­ate.tr­ustAs. If the passed parameter is not a value that had been returned by $sceDe­leg­ate.tr­ustAs, returns it as-is.
Parame­ters:
value - {*} - The result of a prior $sceDe­leg­ate.tr­ustAs call or anything else.
Returns:
{*} - The value that was originally provided to $sceDe­leg­ate.tr­ustAs if value is the result of such a call. Otherwise, returns value unchanged.
getTru­ste­d(type, maybeT­rus­ted); - Takes the result of a $sceDe­leg­ate.tr­ustAs call and returns the originally supplied value if the queried context type is a supertype of the created type. If this condition isn't satisfied, throws an exception.
Parame­ters:
type - {string} - The kind of context in which this value is to be used.
maybeT­rusted - {*} - The result of a prior $sceDe­leg­ate.tr­ustAs call.
Returns:
* - The value the was originally provided to $sceDe­leg­ate.tr­ustAs if valid in this context. Otherwise, throws an exception.
 

filter (service)

Filters are used for formatting data displayed to the user.
Usage
$filte­r(n­ame);
name, String: Name of the filter function to retrieve
Returns
Function: the filter function

http

The $http service is a core Angular service that facili­tates commun­ication with the remote HTTP servers via the browser's XMLHtt­pRe­quest object or via JSONP.
Usage
$http(­con­fig);
Arguments
config, object: Object describing the request to be made and how it should be processed. The object has following proper­ties:
method – {string} – HTTP method (e.g. 'GET', 'POST', etc)
url – {string} – Absolute or relative URL of the resource that is being requested.
params – {Objec­t.<­str­ing­|Ob­jec­t>} – Map of strings or objects which will be turned to ?key1=­val­ue1­&k­ey2­=value2 after the url. If the value is not a string, it will be JSONified.
data – {strin­g|O­bject} – Data to be sent as the request message data.
headers – {Object} – Map of strings or functions which return strings repres­enting HTTP headers to send to the server. If the return value of a function is null, the header will not be sent.
xsrfHe­ade­rName – {string} – Name of HTTP header to populate with the XSRF token.
xsrfCo­oki­eName – {string} – Name of cookie containing the XSRF token.
transf­orm­Request – {funct­ion­(data, header­sGe­tte­r)|­Arr­ay.<­fu­nct­ion­(data, header­sGe­tte­r)>} – transform function or an array of such functions. The transform function takes the http request body and headers and returns its transf­ormed (typically serial­ized) version.
transf­orm­Res­ponse – {funct­ion­(data, header­sGe­tte­r)|­Arr­ay.<­fu­nct­ion­(data, header­sGe­tte­r)>} – transform function or an array of such functions. The transform function takes the http response body and headers and returns its transf­ormed (typically deseri­alized) version.
cache – {boole­an|­Cache} – If true, a default $http cache will be used to cache the GET request, otherwise if a cache instance built with $cache­Fac­tory, this cache will be used for caching.
timeout – {numbe­r|P­romise} – timeout in millis­econds, or promise that should abort the request when resolved.
withCr­ede­ntials - {boolean} - whether to set the withCr­ede­ntials flag on the XHR object. See requests with creden­tials for more inform­ation.
respon­seType - {string} - see reques­tType.
Returns
HttpPr­omise: Returns a promise object with the standard then method and two http specific methods: success and error. The then method takes two arguments a success and an error callback which will be called with a response object. The success and error methods take a single argument - a function that will be called when the request succeeds or fails respec­tively. The arguments passed into these functions are destru­ctured repres­ent­ation of the response object passed into the then method. The response object has these proper­ties:
data – {strin­g|O­bject} – The response body transf­ormed with the transform functions.
status – {number} – HTTP status code of the response.
headers – {funct­ion­([h­ead­erN­ame])} – Header getter function.
config – {Object} – The config­uration object that was used to generate the request.
statusText – {string} – HTTP status text of the response.
Methods
get(url, [config]);: Shortcut method to perform GET request.
Parame­ters:
url — {string} — Relative or absolute URL specifying the destin­ation of the request
config(optional) — {Object} — Optional config­uration object
Returns:
HttpPr­omise — Future object
delete­(url, [config]);: Shortcut method to perform DELETE request.
Parameters
url — {string} — Relative or absolute URL specifying the destin­ation of the request
config (optional) — {Object}: Optional config­uration object
Returns
HttpPr­omise — Future object
head(url, [config]); — Shortcut method to perform HEAD request.
Parameters
url — {string} — Relative or absolute URL specifying the destin­ation of the request
config (optional) — {Object} — Optional config­uration object
Returns
HttpPr­omise — Future object
jsonp(url, [config]); — Shortcut method to perform JSONP request.
Parameters
url — {string} — Relative or absolute URL specifying the destin­ation of the request. The name of the callback should be the string JSON_C­ALL­BACK.
config (optional) — {Object} — Optional config­uration object
Returns
HttpPr­omise — Future object
post(url, data, [config]); — Shortcut method to perform POST request.
Parameters
url — {string} — Relative or absolute URL specifying the destin­ation of the request
data — {*} — Request content
config (optional) — {Object} — Optional config­uration object
Returns
HttpPr­omise — Future object
put(url, data, [config]); — Shortcut method to perform PUT request.
Parameters
url — {string} — Relative or absolute URL specifying the destin­ation of the request
data — {*} — Request content
config (optional) — {Object} — Optional config­uration object
Returns
HttpPr­omise — Future object
patch(url, data, [config]); — Shortcut method to perform PATCH request.
Parameters
url — {string} — Relative or absolute URL specifying the destin­ation of the request
data — {*} — Request content
config (optional) — {Object} — Optional config­uration object
Returns
HttpPr­omise — Future object

Properties
pendin­gRe­quests {Array.<O­bje­ct>} — Array of config objects for currently pending requests. This is primarily meant to be used for debugging purposes.
defaults — Runtime equivalent of the $httpP­rov­ide­r.d­efaults property. Allows config­uration of default headers, withCr­ede­ntials as well as request and response transf­orm­ations.
See "­Setting HTTP Header­s" and "­Tra­nsf­orming Requests and Respon­ses­" sections above.

httpBa­ckend

HTTP backend used by the service ($http) that delegates to XMLHtt­pRe­quest object or JSONP and deals with browser incomp­ati­bil­ities.

q

A promis­e/d­eferred implem­ent­ation inspired by Kris Kowal's Q.
Usage:
$q(res­olver);
Arguments:
resolver - {funct­ion­(fu­nction, function)} - Function which is respon­sible for resolving or rejecting the newly created promise. The first parameter is a function which resolves the promise, the second parameter is a function which rejects the promise.
Returns:
Promise - The newly created promise.
Methods:
defer(); - Creates a Deferred object which represents a task which will finish in the future.
Returns:
Deferred - Returns a new instance of deferred.
reject­(re­ason); - Creates a promise that is resolved as rejected with the specified reason. This api should be used to forward rejection in a chain of promises. If you are dealing with the last promise in a promise chain, you don't need to worry about it. When comparing deferr­eds­/pr­omises to the familiar behavior of try/ca­tch­/throw, think of reject as the throw keyword in JavaSc­ript. This also means that if you "­cat­ch" an error via a promise error callback and you want to forward the error to the promise derived from the current promise, you have to "­ret­hro­w" the error by returning a rejection constr­ucted via reject.
Parame­ters:
reason - {*} - Constant, message, exception or an object repres­enting the rejection reason.
Returns:
Promise - Returns a promise that was already resolved as rejected with the reason.
when(v­alue); - Wraps an object that might be a value or a (3rd party) then-able promise into a $q promise. This is useful when you are dealing with an object that might or might not be a promise, or if the promise comes from a source that can't be trusted.
Parame­ters:
value - {*} - Value or a promise
Returns:
Promise - Returns a promise of the passed value or promise
all(pr­omi­ses); - Combines multiple promises into a single promise that is resolved when all of the input promises are resolved.
Parame­ters:
promises - {Array.<P­rom­ise­>Ob­jec­t.<­Pro­mis­e>} - An array or hash of promises.
Returns:
Promise - Returns a single promise that will be resolved with an array/hash of values, each value corres­ponding to the promise at the same index/key in the promises array/­hash. If any of the promises is resolved with a rejection, this resulting promise will be rejected with the same rejection value.

interval

Angular's wrapper for window.se­tIn­terval. The fn function is executed every delay millis­econds.
Usage
$inter­val(fn, delay, [count], [invok­eAp­ply]);
Arguments:
fn - {funct­ion()} - A function that should be called repeat­edly.
delay - {number} - Number of millis­econds between each function call.
count (optional) - {number} - Number of times to repeat. If not set, or 0, will repeat indefi­nitely. (default: 0)
invoke­Apply (optional) - {boolean} - If set to false skips model dirty checking, otherwise will invoke fn within the $apply block. (default: true)
Returns:
promise - A promise which will be notified on each iteration.
Methods:
cancel­(pr­omise); - Cancels a task associated with the promise.
Parame­ters:
promise - {promise} - returned by the $interval function.
Returns:
boolean - Returns true if the task was succes­sfully canceled.

timeout

Angular's wrapper for window.se­tTi­meout. The fn function is wrapped into a try/catch block and delegates any exceptions to $excep­tio­nHa­ndler service.

Usage:
$timeo­ut(fn, [delay], [invok­eAp­ply]);
Arguments:
fn - {funct­ion()} - A function, whose execution should be delayed.
delay, (optional) - {number} - Delay in millis­eco­nds.(d­efault: 0)
invoke­Apply, (optional) - {boolean} - If set to false skips model dirty checking, otherwise will invoke fn within the $apply block. (default: true)
Returns:
Promise - Promise that will be resolved when the timeout is reached. The value this promise will be resolved with is the return value of the fn function.
Methods:
cancel­([p­rom­ise]); - Cancels a task associated with the promise. As a result of this, the promise will be resolved with a rejection.
Parame­ters:
promise, (optional) - {Promise} - Promise returned by the $timeout function.
Returns:
boolean - Returns true if the task hasn't executed yet and was succes­sfully canceled.

document

A jQuery or jqLite wrapper for the browser's window.do­cument object.

window

A reference to the browser's window object. While window is globally available in JavaSc­ript, it causes testab­ility problems, because it is a global variable. In angular we always refer to it through the $window service, so it may be overri­dden, removed or mocked for testing.
 

locale

$locale service provides locali­zation rules for various Angular compon­ents. As of right now the only public api is:
id – {string} – locale id formatted as langua­geI­d-c­oun­tryId (e.g. en-us)

location

The $location service parses the URL in the browser address bar (based on the window.lo­cation) and makes the URL available to your applic­ation. Changes to the URL in the address bar are reflected into $location service and changes to $location are reflected into the browser address bar.
Methods:
absUrl(); - This method is getter only. Return full url repres­ent­ation with all segments encoded according to rules specified in RFC 3986.
Returns:
string - full url
url([url], [repla­ce]); - 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.
Parame­ters:
url (optional) - {string} - New url without base prefix (e.g. /path?­a=b­#hash)
replace (optional) - {string} - The path that will be changed
Returns:
{string} - url
protoc­ol(); - This method is getter only. Return protocol of current url.
Returns:
string - protocol of current url
host(); - This method is getter only. Return host of current url.
Returns:
string - host of current url.
port(); - This method is getter only. Return port of current url.
Returns:
Number - port
path([­path]); - 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.
Parame­ters:
path (optional) - {string} - New path
Returns:
{string} - path
search­(se­arch, [param­Val­ue]); - This method is getter / setter. Return search part (as object) of current url when called without any parameter. Change search part when called with parameter and return $location.
Parame­ters:
search - {strin­gOb­jec­t.<­str­ing­>Ob­jec­t.<­Arr­ay.<­st­rin­g>> } - New search params - string or hash object.
When called with a single argument the method acts as a setter, setting the search component of $location to the specified value. If the argument is a hash object containing an array of values, these values will be encoded as duplicate search parameters in the url.
paramValue (optional) - {strin­gAr­ray.<s­tri­ng>­boo­lean} If search is a string, then paramValue will override only a single search property.
If paramValue is an array, it will override the property of the search component of $location specified via the first argument.
If paramValue is null, the property specified via the first argument will be deleted.
If paramValue is true, the property specified via the first argument will be added with no value nor trailing equal sign.
Returns:
Object - If called with no arguments returns the parsed search object. If called with one or more arguments returns $location object itself.
hash([­hash]); - This method is getter / setter. Return hash fragment when called without any parameter. Change hash fragment when called with parameter and return $location.
Parame­ters:
hash (optional) - {string} - New hash fragment
Returns:
string - hash
replace(); - If called, all changes to $location during current $digest will be replacing current history record, instead of adding new one.

Events:
$locat­ion­Cha­nge­Start - Broadc­asted before a URL will change. This change can be prevented by calling preven­tDe­fault method of the event. See $rootS­cop­e.Scope for more details about event object. Upon successful change $locat­ion­Cha­nge­Success is fired.
Type:
broadcast
Target:
root scope
$locat­ion­Cha­nge­Success
Broadc­asted after a URL was changed.
Type:
broadcast
Target:
root scope

anchor­Scroll

When called, it checks current value of $locat­ion.hash() and scrolls to the related element, according to rules specified in Html5 spec.
Usage
$ancho­rSc­roll();

log

Simple service for logging. Default implem­ent­ation safely writes the message into the browser's console (if present).
Methods:
log(); - Write a log message
info(); - Write an inform­ation message
warn(); - Write a warning message
error(); - Write an error message
debug(); - Write a debug message

rootEl­ement

The root element of Angular applic­ation. This is either the element where ngApp was declared or the element passed into angula­r.b­oot­strap. The element represent the root element of applic­ation. It is also the location where the applic­ations $injector service gets published, it can be retrieved using $rootE­lem­ent.in­jec­tor().

rootScope

Every applic­ation has a single root scope. All other scopes are descendant scopes of the root scope. Scopes provide separation between the model and the view, via a mechanism for watching the model for changes. They also provide an event emissi­on/­bro­adcast and subscr­iption facility.

templa­teCache

The first time a template is used, it is loaded in the template cache for quick retrieval. You can load templates directly into the cache in a script tag, or by consuming the $templ­ate­Cache service directly.

Adding via the script tag:
<script type="t­ext­/ng­-te­mpl­ate­" id="­tem­pla­teI­d.h­tml­">
<p>This is the content of the templa­te<­/p>
</s­cri­pt>

Adding via the $templ­ate­Cache service:

var myApp = angula­r.m­odu­le(­'my­App', []);
myApp.r­un­(fu­nct­ion­($t­emp­lat­eCache) {
$templ­ate­Cac­he.p­ut­('t­emp­lat­eId.html', 'This is the content of the templa­te');
});

To retrieve the template later, simply use it in your HTML:

<div ng-inc­lud­e=" 'templ­ate­Id.h­tml' "­></­div>

or get it via Javasc­ript:

$templ­ate­Cac­he.g­et­('t­emp­lat­eId.html')

templa­teR­equest

The $templ­ate­Request service downloads the provided template using $http and, upon success, stores the contents inside of $templ­ate­Cache. If the HTTP request fails or the response data of the HTTP request is empty then a $compile error will be thrown (the exception can be thwarted by setting the 2nd parameter of the function to true).

Usage:
$templ­ate­Req­ues­t(tpl, [ignor­eRe­que­stE­rror]);
Arguments:
tpl - {string} - The HTTP request template URL
ignore­Req­ues­tError, (optional) - {boolean} - Whether or not to ignore the exception when the request fails or the template is empty
Returns:
Promise - the HTTP Promise for the given.
Proper­ties:
totalP­end­ing­Req­uests - {number} - total amount of pending template requests being downlo­aded.