Difference between revisions of "AngularJS HTTP module"

From Wiki @ Karl Jones dot com
Jump to: navigation, search
(Created page with "In AngularJS, the HTTP Module provides features for communicating with servers via HTTP. == Description == It simplifies usage of the XHR and JSONP APIs. The HTTP modul...")
 
Line 1: Line 1:
In [[AngularJS]], the HTTP Module provides features for communicating with servers via HTTP.
+
In [[AngularJS]], the Observable implements the [[Observer pattern]].
  
== Description ==
+
== Methods ==
  
It simplifies usage of the XHR and JSONP APIs.
+
* '''.subscribe''' = start and listen to an observable stream.
 +
* '''.onNext''' = called when new data arrives.
 +
* '''.onError''' = called when error is thrown.
 +
* '''.onComplete''' = called when stream is completed.
  
The HTTP module API conveniently matches RESTful verbs.
+
== Compare with promises ==
  
It returns an observable object.
+
Observables are similar to promises.
 +
 
 +
== toPromise ==
 +
 
 +
Observables can be converted to promises using the '''toPromise''' method.
 +
 
 +
== Error handling ==
 +
 
 +
Chain the '''.catch''' method on an Observable.
 +
 
 +
Pass in a callback sign a single '''error''' argument.
  
 
== See also ==
 
== See also ==

Revision as of 15:45, 2 January 2017

In AngularJS, the Observable implements the Observer pattern.

Methods

  • .subscribe = start and listen to an observable stream.
  • .onNext = called when new data arrives.
  • .onError = called when error is thrown.
  • .onComplete = called when stream is completed.

Compare with promises

Observables are similar to promises.

toPromise

Observables can be converted to promises using the toPromise method.

Error handling

Chain the .catch method on an Observable.

Pass in a callback sign a single error argument.

See also

External links