2017-05-19 39 views
0

以下是我用来更新我的列表计数的代码, 它首先在count上工作正常,但随着count改变值的弹性。 例如:如果计数是3在第一和然后计数被3和4

setInterval(function() { 
    if ($scope.listing != undefined && $scope.listing != null) { 
     $rootScope.countsData = $scope.listing.length; 
    } else { 
     $rootScope.countsData = 0; 
    } 
}, 2000); 
+0

格式/缩进你的代码,它是不可读的。 – Mistalis

+0

所以当'count'改为4时,你还想看3吗?为什么? – Hoa

+0

我不想看到3,但它显示3和4。我想只看到4. –

回答

0

之间的计数变量笔触更新为4注入$间隔到控制器,然后更改您的代码此:

$interval(function() { 
    if ($scope.listing) { 
     $rootScope.countsData = $scope.listing.length; 
    } else { 
     $rootScope.countsData = 0; 
    } 
}, 2000); 
+0

我已经实现了这个,让我们看看它是否工作。 –