Good day.
I do ajax on angularjs, but it turns out to be synchronous, and the site hangs.
Example:

$http.get('api/getstudents'). success(function(data, status, headers, config) { $scope.Students= data; }); 

How to make it asynchronous and display the <div>Загрузка...</div> element first, and hide it at the end?

  • @ Roman Rakzin, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Nicolas Chabanovsky

2 answers 2

So what's the problem? The get method is asynchronous, that is, it already solves the problem.

template

 <div> {{ data }} </div> 

code

 $scope.data = "Загрузка"; $http.get('api/getstudents'). success(function(data, status, headers, config) { $scope.data = data; }); 

    The request is asynchronous, and the site should not hang entirely. Well, in order to show the inscription "loading ...", until the data is loaded, you can use the ng-show or ng-hide directives.

     <div ng-hide="Students">Загрузка...</div> <div ng-repeat="student in Students">{{student.name}}</div> 

    Something like this.