我有一个$scope.event
当我从服务器收到数据时我正在推送数据,我正在使用angularjs进度条,所以基于用户交互我想开始记录数据,所以当数据开始记录时我想要创建像$scope.progressbarData
这样的新数组,这样我就可以设置进度条的动态值。
ctrl.js
$scope.event = [];
$scope.progressbarData = [];
$scope.dynamic = 0;
$scope.max = 200;
socket.on('ditConsumer',function (data) {
var obj = {
file:$scope.filename,
data:data
}
$scope.event.push(data);
if(sendMessageFlag === true) {
$scope.dynamic = $scope.event.length;
return sendMessageToFile(obj);
}
});
main.html中
<div class="row">
<div class="col-md-10">
<uib-progressbar max="max" animate="true" value="dynamic">{{dynamic}} / {{max}}</uib-progressbar>
</div>
</div>
答案 0 :(得分:1)
您可以在事件处理程序中添加另一个Array.push()。这是可读的,并且在这种情况下是标准方法。
$scope.event = [];
$scope.progressbarData = [];
$scope.dynamic = 0;
$scope.max = 200;
socket.on('ditConsumer',function (data) {
var obj = {
file:$scope.filename,
data:data
}
$scope.event.push(data);
$scope.progressbarData.push(data);
if(sendMessageFlag === true) {
$scope.dynamic = $scope.event.length;
return sendMessageToFile(obj);
}
});