2017-08-31 49 views
0

我的ng-repeat中有input fieldmatch in matchList。我希望能够点击输入字段并显示这个复选框被点击的次数。它正在工作,但有一个问题。AngularJS - 专注于ng-repeat中的输入字段

当我点击输入字段时,焦点从0-1开始计数,但是对于每个对象,都有ng-repeat。我只想显示点击输入字段的计数。所以我需要给输入字段一个ng-model来得到点击的输入字段数。

这是我的NG-重复我的输入字段:

<input ng-model="??" ng-focus="focusEvent()" type="number" min="0" max="9" step="1" ng-value="'{{ match[2] }}'"> 

这是我的控制器:

app.controller('gametableController', ['currentAuth', '$scope', '$location', '$firebaseObject', '$firebaseArray', '$http', 'cfpLoadingBar', function (currentAuth, $scope, $location, $firebaseObject, $firebaseArray, $http, cfpLoadingBar) { 
    $scope.versus = 'VS'; 
    $scope.onMobileInfo = 'Der Spielplan wird nur auf einem größeren Bereich angezeigt.'; 
    $scope.timesFocused = 0; 
    $scope.isFocused = false; 

    var ref = firebase.database().ref("matches"); 
    var matchList = $firebaseObject(ref); 

    matchList.$loaded().then(function() { 

     cfpLoadingBar.start(); 

     $scope.matchList = []; 

     angular.forEach(matchList, function (match) { 

      var matchTeams = []; 

      angular.forEach(match, function (team) { 
       matchTeams.push(team) 
      }); 

      $scope.focusEvent = function() { 
       $scope.timesFocused++; 
      }; 

      $scope.focusInput = function() { 
       $scope.isFocused = !$scope.isFocused; 
      }; 

      $scope.matchList.push(matchTeams); 
     }); 

     cfpLoadingBar.complete(); 

    }); 

}]); 

回答

0

如何执行以下操作:

  • 首先初始化一个长度为的数组您从Firebase收到的数据阵列 。
  • 其次,你只需要声明的每个输入,其中 它采用可变的ID或$指数作为参数(东西 像ng-click="incrementInput(match.id)
  • 和功能在里面你会内部递增值ng-click功能阵列 (每个示例(arrayOfMatches[match.id] += 1