Non-Flickering Polling in Angular with REST Backend

只谈情不闲聊 提交于 2019-12-06 01:52:29

问题


I managed getting a constant polling of the backend functional using this answer.

But on every timeout the UI is flickering (empty model for a short time). How can I update the model (and the view respectively) after the new data arrived in order 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'm using the current stable 1.0.6 of Angular.js


回答1:


Try updating the data in the success callback. Something like this:

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

This should prevent the flicker that is occurring when $scope.line is empty as the Model resource is fetching the data.



来源:https://stackoverflow.com/questions/16352690/non-flickering-polling-in-angular-with-rest-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!