javascript - Simultaneous asynchronous requests in AngularJS containing inner operation -


How do I create 2 asynchronous requests in AngularJS after which the first request should be made? ?

I have to do something like this:

  • Call the first web service (get x)
  • Call another web service
  • I have to do something after both data (G (X, Y) I
  • Do some things before I get feedback from the web service (F) (X))

The following approach:

  $ q.all ({x: $ http.get ('http: // sourceX'), y: $ Http.get ( 'Http: // sourceY')}). Then (function (result) {$ scope.a = f (results.x.data); // where is it to keep the line? $ Scope.z = g (results.x.data, results.y.data) ;});  

is not efficient because it is waiting for the resource even if the resource has been received.

I would like to call the function when x is available and when x and y are available, call the function g

A phony code looks like this for what I want:

  $ q.all ({X: $ http.get ('http: // sourceX '), Y: $ http.get (' http: // sourceY ')}). When (x is ready) {$ scope.a = f (result x.data); }). Then (function (result) {$ scope.z = g (results.x.data, results.y.data);});  

Therefore, give me the $ q.all approach and

  $ http.get ('http: // sourceX') .success (function (x) {$ scope.a = f (x); $ http.get ('http: // sourceY') .succes (function (y) {$ scope.z = g (x, y) ;});});  

You can isolate calls like this:

  Y wardX = $ http.get ('http: // sourceX'); Var wired y = $ http.get ('http: // sourceY'); PromiseX.then (function {$ scope.a = f (result.data);}); $ q.all ({x: watted x, y: wired y}). Then (function (result) {$ scope .z = g (results.x.data, results.y.data);});  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -