I copied a working solution in another page, but for some reason it does not work; this is a test code:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-controller="MyCtrl" ng-app="myapp">
<table name="commentsTable">
<tr ng-repeat="item in items = obj track by $index">
<td class="plantCell">{{items[$index].nome}}: </td>
<td class="statusCell">{{items[$index].status}}</td>
<td class="statusCell">{{items[$index].testo}}</td>
</tr>
</table>
</div>
<script language="javascript">
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 = [{
"nome": "first",
"status": 1,
"testo": "Rottura rullo 1!!!"
}, {
"nome": "second",
"status": 0,
"testo": "Rottura rullo fsdfsf!!!"
}];
console.log("ricevo evento");
console.log($scope.obj);
}
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>
For some reason all that appears is:
{{items[$index].nome}}: {{items[$index].status}} {{items[$index].testo}}
I have the following errors, like if the assignment were never made:
printOperation is not a function
function ($scope) never called.
Like if the angular library were not loaded. What is wrong?