angularjs - Angular $htttp : to which asynch call did I get the reply? -


I go to a server and a lat / long pair & amp; Some other information (for example vehicle details, time stamp). For each of them, I want to use Google Maps so that GOCOD & amp; Find out the road then insert it into the ng-grid.

My ng-grid is bound to $ scope.myGrid and so far, without reverse geo encoding, I am still json data and $ scope.myGrid.push ( '{When: Data: [i]. Time_Stamp, Vehicle: Data [i]. Description'}} .

> It was working fine, now I have to do reverse geocoding I want to add, which means to use AFAIK, $ http.get .

Since it is asynchronous, I initially found the grid's "address" "[address available No] "with" "column.

I get set up, so I want to set $ scope.myGrid [???] address to .

But , how do I know What is that index ??? ? If I have 3 excellent asyn requests and receive a response, then how do I know which grid line corresponds to? < p> My $ http.get for a (var i = 0; i & lt; data.length; I ++) loop. Can I send i to $ http.get fuke? Or how do I do this?

Sorry, I'm learning now.

If you want to use 'for', you can do this by using the Anonymous Function Have to use. Pass the anonymous function I

 for  (var i = 0; i scope.myGrid.length; i ++) {(function (i) {$ http.get (...). Success (work) {$ scope.myGrid [i] .address = data});}) (i); }   

IMHO, probably better in your case for "every unit"

  $ scope.myGrid.forEach (function (item, i) {/ / Item equals $ Scope.myGrid [i] $ http.get (...) success (function (data) {item.address = data});});    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -