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.
我有一个angular.js表(使用智能表模块/插件),我正在尝试根据窗口中设置的一些数据更新它,特别是如何设置数据。
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.js表中
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.
理论上它应该自动抓取window.checker.checked并填写结果,在某个地方没有发生的事情和我目前的角度知识是没有帮助我找到任何解决方案。
1 个解决方案
#1
1
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
setInterval希望获得对函数的引用,但是在这里你直接调用它。您可以通过将x定义放入匿名函数或仅在setInterval中将x定义为函数回调来修复它
#1
1
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
setInterval希望获得对函数的引用,但是在这里你直接调用它。您可以通过将x定义放入匿名函数或仅在setInterval中将x定义为函数回调来修复它