这真的很奇怪......所以我突然设置并在控制器中多次重新设置的变量突然不再允许自行重置。
控制器:
$scope.classIndex = 0;
$scope.classNum = function(i){
$scope.classIndex = i;
//do other stuff with $scope.classIndex
//// This one wont update classIndex i.e. functions called with it always
////show classindex as 0
}
$scope.viewClass = function(i){
$scope.classIndex = i;
//do other stuff with $scope.classIndex //// BUT !!?? This one works fine
}
HTML
////inside an ng repeat ... hence $index
<div class="btn-group col-xs-10 col-xs-offset-1" ng-show="options">
<button class="btn btn-xs btn-info btn-flat col-xs-6" ng-click="viewClass($index)"><i class="fa fa-info-circle"></i> View </button>
<button class="btn btn-xs btn-danger btn-flat col-xs-6" ng-click="classNum($index)"><i class="fa fa-trash-o"> Delete</i></button>
</div>
所以基本上我的视图按钮显示正确的项目,但删除总是删除索引[0]的项目。
有什么想法吗?
编辑:这显然是一个错误。我将代码复制到一个新文件,上传到服务器,它突然又开始工作......
答案 0 :(得分:1)
如果你没有在任何Html页面中使用该变量,请使用它 只有那个js控制器然后以给定的方式执行它。的:强>
var classIndex = 0;
$scope.classNum = function(i){
classIndex = i;
//do other stuff with $scope.classIndex
//// This one wont update classIndex i.e. functions called with it always
////show classindex as 0
}
$scope.viewClass = function(i){
classIndex = i;
//do other stuff with $scope.classIndex //// BUT !!?? This one works fine
}