Professional Documents
Culture Documents
- Day 8
By
George
Agenda
$emit
The event life cycle starts at the scope on which $emit was called.
The event traverses upwards toward the root scope and calls all registered
listeners along the way
The event will stop propagating if one of the listeners cancels it.
$emit
$broadcast
It dispatches an event name downwards to all child scopes (and
The event life cycle starts at the scope on which $broadcast was
called.
And, calls all registered listeners along the way. The event cannot be
canceled.
$broadcast
$on
It listen on events of a given type. It can
catch the event dispatched by $broadcast
and $emit.
$interval
$interval services is similar to JavaScript setInterval() functions . And, the
functionality is also similar
$timeout
Injecting $timeout
$interval
Injecting $interval
$http
The $http service is the easiest way to send AJAX calls to your web server
The $http legacy promise methods success and error have been
deprecated. Use the standard then method instead
$http.get(url, config)
$http.delete(url, config)
$http.head(url, config)
GET:
The GET method means retrieve whatever information (in the form of an entity) is identified by the RequestURI
HEAD:
The HEAD method is similar to GET except that the server MUST NOT return a message-body in the
response
POST:
The POST method is used to provide a block of data to server -- And, then the server will manupulate the
data and save them into the DB and give the response back
PUT:
DELETE:
The DELETE method requests that the origin server delete the resource identified by the Request-URI
$http as a Function
Use the $http service as a function directly
var promise = $http(config);
The config parameter passed to the different $http functions controls the HTTP
request sent to the server. The config parameter is a JavaScript object which can
contain the following properties:
method
url
params
headers
timeout
cache
transformRequest
transformResponse
The method property can be used to set the HTTP method for the request.
This property is normally set implicitly via the function you choose to call on the $http service
url:
The url property can be used to set the URL of the AJAX call.
parms:
The params property is used to set any additional request parameters to be appended to the URL
query string.
The params property is a JavaScript object with one property per request parameter to add.
$resource
A factory which creates a resource object
that lets you interact with RESTful serverside data sources.
Built on the top of the $http service
Angulars $resource is a factory that lets
you interact with RESTful backends easily.
$resource CURD
Prerequisites
The $resource service doesnt come bundled with the main Angular script.
The result of the function call is a resource class object which has the following five
methods by default:
get()
query()
save()
remove()
delete()
put method
stripTrailingSlashes
By default this is set to true, which means trailing slashes will be removed from
the URL you pass to $resource().
$q Services
A service that helps you run functions asynchronously, and use their return values (or
exceptions) when they are done processing.
$q Services..