>
> There is no technical need to do async outside an repeat.

Sander, the OP, in fact, DOES have an async call ($http) INSIDE an 
ng-repeat.  THAT is absolutely a no-no . So I'm not clear with what you are 
saying.

.. the user has to wait for every thumbnail to arrive

That is absolutely correct, especially with the setup the OP has.  Take 
note the OP is using a manual 'submit' to populate the table so 'waiting' 
is built in anyway. *In the alternate (and possibly more realistic) case,* 
that the controller already has an array of videos to request thumbnail 
URLs, then they can be sent en masse through a SINGLE $http and ALL the 
image URLS will return en masse as well.  In this alternate case, the 
program can rapidly populate the screen once the async $http returns with a 
promise. But this is still synchronous and DOM manipulation can only be 
performed after the promise/callback however long it takes.  Additionally 
that is EXACTLY what promises/callbacks are for.

But putting asynchronous  in a factory, doesn't make it work synchronous, 
> so the problem stays the same.

That is correct but again, however, I'm not clear how it relates to this 
topic.  I merely mentioned it as an architectural concern As you imply, 
the venue for the service vs controller is irrelevant to the notion of 
asynchronicity.

To conclude, the concept is nuanced but crucial and universal: Once you 
invoke $http, then you have spun off a separate thread from your main 
thread (main UI) and, as asynchronicity dictates, you can only take action 
on the DOM (main thread) once (if ever) the promise calls back successfully 
(or not).

More on this:
https://github.com/angular/angular.js/issues/3196
http://stackoverflow.com/questions/20137350/angular-service-containing-http-get-call-not-working-with-ng-repeat

Mo

On Friday, May 29, 2015 at 3:31:55 PM UTC-4, Sander Elias wrote:
>
> hi Mo,
>  
>
>> NOTE: To reiterate, the key here is to push the video object to your 
>> array AFTER the async $http completes.
>>
> Not really needed. If you look at my sample, it will just work, and the 
> table gets enriched with thumbnails as they come in. There is no technical 
> need to do async outside an repeat. It all depends on use-case.
> I do agree that you shouldn't have $http inside an controller, you are 
> better of if you put it in a factory. But putting asynchronous  in a 
> factory, doesn't make it work synchronous, so the problem stays the same.
> When you make the thing like you propose, the user has to wait for every 
> thumbnail to arrive, before getting anything on screen. I think that's a 
> bad idea. Might work fine if you have up to 4 thumbs, but imagine your 
> search return 100 hits? 
> (and there you have an reason too be able to cancel $http requests. That's 
> challenging in angular 1.x ;) )
>
>
> Regards
> Sander
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to