In the html file there are tags for displaying information:

<div class="container" ng-controller="MainController"> <span class="blc" ng-repeat="process in processess"> <i class="fa fa-space-shuttle"></i> <span class="p-left ">{{ process.caption }}</span> </span> </div> 

What to do, tell me how to properly handle ng-repeat when processing ajax-ohm?

 app.controller('MainController', ['$scope', function($scope) { /* если оставить так, то данные выведутся, ибо они уже присутствуют при загрузке страницы $scope.processess = [ {caption: "ОПИСАНИЕ_1"}, {caption: "ОПИСАНИЕ_2"} ]; */ // однако, данные лежат в базе, и я их вытаскиваю через jquery.ajax + custom service.processtypes().then(function(data){ // $scope.processess не отрабатывает и не отображается на странице $scope.processess = [ {caption: data[0]}, {caption: data[1]} ]; }); }]); 

What to do, tell me how to properly handle ng-repeat when processing ajax-ohm?

  • This is the usual practice - when the answer comes, the view is redrawn, although it depends on the content of service.processtypes - Grundy
  • one
    add an example of the contents of service.processtypes - Grundy
  • add $ scope. $ digest () after $ scope.processess to start the digest cycle of the angulyar - zhenyab
  • add inside the console.log (data) function to understand what is there for the data. - Marat Batalandabad
  • one
    @Grundy is a perfectly fair point. One should avoid using $ digest and even more so $ apply - zhenyab

3 answers 3

if the length of the data array is not constant, then it is better to do so.

 service.processtypes().then(function(data){ $scope.processess = data.map(function(item){ return {"caption":item}; }); }); 

and in html try to do so, then maybe get rid of $ apply

 <span class="blc" ng-repeat="process in processess track by $index"> 
  • one
    But the point is to do so? Moreover, it is better to use the map method here, which is exactly intended for obtaining a new array based on the source - Grundy
  • I did not know about the map, thanks, corrected. And the meaning is obvious. - Marat Batalandabad
  • one
    In general, the $ apply method does not get rid of the answer. Because the problem is not in the array, but in service.processtypes - Grundy
  • I thought it made no sense to make a map. About trak by $ index is so guess. - Marat Batalandabad
  • well, I talked about that forEach and said, because at first I did not understand why he :-) - Grundy
 $scope.$apply(); 

the method helped a lot

  • $ digest is better, the cycle will be shorter, unless $ scope.processess appear somewhere higher - zhenyab

Because

I pull through jquery.ajax + custom

Angulyar does not know that the request has ended, the data has been updated and the corresponding view needs to be updated.

There are many possible solutions: call $ digest , wrap the $ apply function, use the $ timeout service

But the best solution is to use the built-in $ http service for requests, when receiving a response, the angular will do the necessary actions and update the view itself if necessary.