After setting some data in the window, I am facing issues with updating an angular.js table created using the smart table module/plugin. The data is structured like this:
window.checker={};window.checker.checked = [{'ip':9,'port':0}]
I am attempting to load this data into my angular.js table with the following code snippet:
angular.module('myApp', ['smart-table'])
.controller('mainCtrl', ['$scope', function ($scope) {
setInterval(x($scope), 1000)
function x($scope){
function createRandomItem(ip, port) {
var
firstName = ip,
lastName = port,
age = Math.floor(Date.now() / 1000)
return{
firstName: firstName,
lastName: lastName,
age: age
};
}
$scope.displayed = [];
if (window.checker && window.checker.checked) {
for (var j = 0; j < window.checker.checked.length; j++) {
$scope.displayed.push(createRandomItem(window.checker.checked[j].ip, window.checker.checked[j].port));
}
}
}
}])
.directive('stRatio',function(){
return {
link:function(scope, element, attr){
var ratio=+(attr.stRatio);
element.css('width',ratio+'%');
}
};
});
Although the code should automatically fetch and display the data from window.checker.checked, it is not working as expected. My current understanding of angular.js seems insufficient to troubleshoot this issue effectively.