Reputation:
I have a angular.js table (using the smart table module/plugin) and I'm trying to update it based on some data thats getting set in the window, in particular heres how the data is set out.
window.checker={};window.checker.checked = [{'ip':9,'port':0}]
then I'm trying to load that data into my angular.js table using this code below
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+'%');
}
};
});
in theory it should auto grab window.checker.checked and fill in the results, somewhere down the line that is not happening and my current knowledge of angular is'nt helping me find any solutions.
Upvotes: 0
Views: 47
Reputation: 8300
I see a potential problem in this line
setInterval(x($scope), 1000)
setInterval
expects to get a reference to a function but here you are directly calling it. You can fix it either by putting the x
definition into an anonymous function or just defining x
as a function callback directly in setInterval
Upvotes: 1