我使用socket.io
来自服务器的数据为了测试目的,我希望在收到数据后多次生成数据,因此一旦收到消息,我想将其绑定到ng-repeat 5次。是否可以使用angularJs实现?
ctrl.js
angular.module('App').controller('DitCtrl',function ($scope,$rootScope,DitFactory,FileSaver,Blob,socket,$uibModal,searchFactory,$timeout) {
'use strict';
$scope.event = [];
socket.on('Consumer',function (data) {
safelyAdd({
id:$scope.event.length,
value: data
});
for (i = 0; i < 5; i++) {
text += $scope.event.value + i + "<br>";
}
});
});
function safelyAdd(element){
if(totalRecieved > Bufferlimit){
$scope.event =[];//reset array if max size reached..
totalRecieved = 0;
}
$scope.event.push(element); //then push new item..
}
main.html中
<ul style="list-style: none;">
<li ng-repeat="message in event | limitTo:1000" ng-class="{lastItem: $last}"><span><strong>Log:</strong></span><span>{{message.value}}</span></li>
</ul>
答案 0 :(得分:0)
如果你只想将它绑定到ng-repeat 5次,你可以$scope.event.push(element);
5次。