2017-08-31 51 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