【发布时间】:2017-08-04 00:18:54
【问题描述】:
当收到来自 websocket 的数据时,我需要填充一个角度表:我尝试过:
<div ng-controller="MyCtrl" ng-app="myapp">
<table ng-table="commentsTable">
<tr ng-repeat="item in obj track by $index">
<td class="plantCell">{{item.nome}}: </td>
<td class="statusCell">{{item.status}}</td>
<td class="statusCell">{{item.testo}}</td>
</tr>
</table>
</div>
<script>
var app=angular.module('myapp', []);
var printOperation;
function GetFromLocalStorage(key) {
var items=localStorage.getItem(key);
console.log(items);
if (items===null){
console.log("item null");
return null;
} else {
if (typeof items!= "string") {items = JSON.stringify(items);}
return items;
}
}
app.controller('MyCtrl',
function ($scope) {
$scope.printComments=function (){
$scope.obj=GetFromLocalStorage("AllComments");
console.log("ricevo evento e ricarico tabella");
console.log($scope.obj);
//$scope.commentsTable.reload();
}
console.log("assegno print operation");
printOperation=$scope.printComments;
}
);
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
eventer(messageEvent,function(e) {
console.log("ricevo messaggio");
printOperation();
},false);
<script>
未捕获的类型错误:无法读取未定义的属性“重新加载” 在 $scope.printComments ((index):68) 在(索引):80
【问题讨论】:
标签: javascript angularjs html-table