Javascript 如何使用angularJs多次打印变量值?
我有来自服务器的数据,使用Javascript 如何使用angularJs多次打印变量值?,javascript,angularjs,Javascript,Angularjs,我有来自服务器的数据,使用socket.io进行测试,我想在收到消息后多次生成数据,所以一旦收到消息,我想将其绑定到ng重复5次。可以使用angularJs实现吗 ctrl.js angular.module('App').controller('DitCtrl',function ($scope,$rootScope,DitFactory,FileSaver,Blob,socket,$uibModal,searchFactory,$timeout) { 'use strict';
socket.io
进行测试,我想在收到消息后多次生成数据,所以一旦收到消息,我想将其绑定到ng重复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..
}
angular.module('App').controller('DitCtrl',function($scope、$rootScope、DitFactory、FileSaver、Blob、socket、$uibModal、searchFactory、$timeout){
"严格使用",;
$scope.event=[];
socket.on('Consumer',函数(数据){
安全添加({
id:$scope.event.length,
值:数据
});
对于(i=0;i<5;i++){
text+=$scope.event.value+i+“
”;
}
});
});
功能安全添加(元素){
如果(总接收>缓冲限制){
$scope.event=[];//如果达到最大大小,则重置数组。。
总接收量=0;
}
$scope.event.push(元素);//然后推送新项。。
}
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>
- 日志:{{message.value}
如果您只想将它绑定到ng repeat 5次,您只需执行$scope.event.push(元素)代码>5次。您想要多次显示的确切内容是什么?为什么要这样做?我想多次显示一个字符串以进行测试。您需要提供更多代码。。$scope.event
来自哪里?复制完整控制器请添加我的控制器$scope.event是我插入对象的数组什么是安全添加
?此外,当您尝试在视图中显示文本
变量时,您的
将显示为文本字符串。如果需要换行符,请直接将其添加到HTML中。