无闪烁轮询角与REST后端 [英] Non-Flickering Polling in Angular with REST Backend

查看:115
本文介绍了无闪烁轮询角与REST后端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法让使用后端功能的恒定轮询
这个答案。

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

但在每超时在UI闪烁(短时间空模型)。
我怎样才能更新模型(分别视图)的 的到达新的数据后,
为了避免这种闪烁的效果呢?

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?

下面是我的电流控制器(从 step_11(Angular.js教程略有修改)):

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);
    });
})();

}

//编辑:我使用的是当前稳定Angular.js的1.0.6

// edit: I'm using the current stable 1.0.6 of Angular.js

推荐答案

尝试在成功回调更新数据。事情是这样的:

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);
    });
})();

这应该prevent当 $ scope.line 是空的,因为模型的资源是获取数据。

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

这篇关于无闪烁轮询角与REST后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆