1

I am using Angular 1.4.7 with angular-ui-router 0.2.15 as state router. My standard controller looks like:

var app = angular.module('App.Page1',[....]);
app.controller('Page1Ctrl',['$scope' ... ,function($scope ...) {
...
  $scope.records = [];

  // jsRoutes.controllers.Page1.list() - is ajax wrapper
  jsRoutes.controllers.Page1.listitems().ajax({
    success: function(data) { 
       console.log("RECV",data);
       $scope.records = data 
    },
    error: function(res){ console.log("ERROR",res); }
  });
});

And controller template that just rolls out records:

<h1>Page1</h1>
<div ng-repeat="record in records" class="row">
    {{record.name}} ...
</div>

It works but not stable. Sometimes I am receiving a page only with the header. Looks like parsers array is empty but I see in Network requests that list request was successfully received and success function was called. After refreshing a page, I see my data again.

1 Answer 1

2

Your ajax service call is outside the context of AngularJS. Hence you need to explicitly inform Angular that some data has changed.

This can be done calling $scope.$apply() in your success function after you assign data to your $scope variable.

$scope.parsers = data; $scope.$apply();

This should solve your issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.