Show list after request finished


#1

Hi there,

how can I refresh a list after my data has arrived from the server?
I display a spinner with ngif until the content is loaded, but my list remains empty

	$http.post(requestURL, {'sessions':sessions}).
	success(function(data, status, headers, config) {
		  scope.predictionInProgress = false;
		  scope.predictedSessions = data;
	}).
	error(function(data, status, headers, config) {
	  
	});
	<ion-spinner ng-if="predictionInProgress" icon="lines"/>
	
	<ion-list>
	  	<ion-item nav-clear menu-close ng-repeat="session in predictedSessions">
          {{session.name}}
        </ion-item>
    </ion-list>

#2

Don’t you think it should be $scope and not scope?


#3

Most likely yes. You usually would only use “scope” if somewhere else you’ve defined it as such (like in a directive). Try out $scope and see what that does. Also in all of my http calls I log the data that way I can make sure that it’s actually sending me what I’m expecting. In safari I can do

console.log("[HTTP] Sessions List: ", data, status, headers, config);

And that will output them all in one log line though I do not know if chrome or firefox have support for the multiple arguments. There are other logging libraries out there that can do this though.


#4

Hi guys,

$scope or scope does not matter in that context. I am asking how to force a modal reload of the list once my request is finished. The alternative that I will implement now is to display a progress modal and display the fully loaded modal when the data comes. Right now I have both in one, to keep it simple spliting it up would probably be better… ?


#5

We’re missing a lot of context here. Is the code above in a controller? In a factory? Do you have a CodePen showing it not working?

Based on the code you’ve shown, it SHOULD change the list when the scope.predictedSessions variable is updated.

But again, hard to debug what we can’t see.