繁体   English   中英

从 controller - angularjs 调用 function

[英]call function from controller - angularjs

im trying to call a simple function in angularjs, but when im calling the function from the controller, the app crash. 例如,如果我从 ng-click 事件中调用 function,则一切正常。

代码是关于 json object 数组,我想将他的数据推送到另一个数组

编码:

$scope.imgindex=[];


$scope.makeindex = function()
{
  for(var i=0;i<$scope.zimmers.length;i++)
  {
    $scope.imgindex.push({id:$scope.zimmers[i]['ZimmerID'],index:0});
  }
}


makeindex();

我们需要知道 object $scope.zimmers才能给您一个明确的答案,但显然您的代码在您尝试访问$scope.zimmers[i]['ZimmerID']变量时出现错误,也许您之前正在尝试访问它是可用的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM