I'm building a simple UI that communicates with my backend server. The UI sends to the server a URL to process, and the server would return a list of results.
Regarding results, each result takes time to calculate, yet I would still like to show the incoming results in the UI, maybe even use ng-repeat on the set of results which will be updated as results are being received from the server.
The problem is, Angular's $http service returns a promise that can only handle success and failure states.
I was wondering if there's some kind of "ongoing" state that I can run a callback function on.
For example, The results are JSON containing an array of results:
{
results: [
{prop1: val1, prop2: val2}, // result 1
{prop1: val1, prop2: val2}, // result 2
{prop1: val1, prop2: val2}, // result 3
{prop1: val1, prop2: val2} // result 4
]
}
Just imagine that it takes 5-6 seconds to calculate before each of the results are ready to be sent in the response.
So, the wanted flow and behavior is this:
UI:
- Sends a
POSTrequest containing all the details required by the server. - On each line received, push the result contained in that line to
$scope.results.
The rest will be done by the digest loop and ng-repeat will make sure I see them on screen.
So the only problem I have, is how do I access the response data while it is being received?
Btw, if you have any suggestions to do it in another way, I'd be glad to hear, as long as it's simple... it is really a simple UI, nothing advanced is needed here.
Thanks a lot.