Non flickering polling in Angular with REST Backend

I managed to get a constant poll of the backend functionality using this answer.

But at each timeout, the user interface flickers (empty model for a short time). How can I update the model (and view, respectively) after new data has appeared to avoid this flickering effect?

Here is my current controller (slightly modified from step_11 (Angular.js Tutorial) ):

function MyPollingCtrl($scope, $routeParams, $timeout, Model) { (function tick() { $scope.line = Model.get({ modelId : $routeParams.modelId }, function(model) { $timeout(tick, 2000); }); })(); } 

// edit: I am using the current stable version 1.0.6 from Angular.js

+6
source share
1 answer

Try updating the data in the callback. Something like that:

 (function tick() { Model.get({ modelId : $routeParams.modelId }, function(model) { $scope.line = model; $timeout(tick, 2000); }); })(); 

This should prevent flickering when $scope.line empty as the resource model is $scope.line data.

+10
source

Source: https://habr.com/ru/post/944174/


All Articles