2017-08-31 107 views
0

目前我有一个对象(队)的列表,我用ng-repeat(在matchList中匹配)显示它们。所以这是8支球队和28场比赛。现在,我在每个想要通过单击输入字段输入结果的团队旁边都有一个输入字段。那时我检查输入字段是否被聚焦(ng-focus & ng-blur)。如何在输入字段聚焦时获取特定对象?

我的问题是,我需要从对象teamname在我的console.log下一个步骤上下工夫...

我怎么能做到呢?

这是我的控制器:

app.controller('gametableController', ['currentAuth', '$scope', '$location', '$firebaseObject', '$firebaseArray', '$http', 'cfpLoadingBar', function (currentAuth, $scope, $location, $firebaseObject, $firebaseArray, $http, cfpLoadingBar) { 

    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.focus = function() { 
       console.log('focussed'); 
      }; 
      $scope.blur = function() { 
       console.log('not focussed') 
      }; 

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

     console.log(matchList); 

     cfpLoadingBar.complete(); 

    }); 

}]); 

这是我的HTML:

<div class="container mrgn-bottom"> 
     <div class="row" ng-repeat="match in matchList"> 
      <div class="col-md-12 mrgn"> 

       <div class="match"> 

        <div class="col-md-3 card-plan card-wrp"> 

         <div class="col-md-3 player-team-logo"><img ng-src="{{match[1]}}" width="60" height="60" class="table-team-logo"></div> 

         <div class="col-md-9"> 
          <div class="col-md-12 player-team-info info-team"><b>{{match[0]}}</b></div> 
          <div class="col-md-12 player-team-info info-user">{{match[3]}}</div> 
          <div class="col-md-12 player-team-info info-user">Siege: {{match[4]}}</div> 
         </div> 
        </div> 

        <div class="col-md-1 result-input-wrp card-plan-result"> 
         <div class="quantity"> 
          <input type="tel" ng-model="model" ng-focus="focus()" ng-blur="blur()" maxlength="2" min="1" max="9" step="1" ng-value="'{{ match[2] }}'" title="result"> 
         </div> 
        </div> 

        <div class="col-md-4"> 
         <div class="versus-text"><b>{{ versus }}</b></div> 
        </div> 

        <div class="col-md-1 result-input-wrp card-plan-result"> 
         <div class="quantity"> 
          <input type="tel" ng-model="model" ng-focus="focus()" ng-blur="blur()" maxlength="2" min="1" max="9" step="1" ng-value="'{{ match[9] }}'" title="result"> 
         </div> 
        </div> 

        <div class="col-md-3 card-plan card-wrp"> 

         <div class="col-md-3 player-team-logo"><img ng-src="{{match[6]}}" width="60" height="60" class="table-team-logo"></div> 

         <div class="col-md-9 "> 
          <div class="col-md-12 player-team-info info-team"><b>{{match[5]}}</b></div> 
          <div class="col-md-12 player-team-info info-user">{{match[8]}}</div> 
          <div class="col-md-12 player-team-info info-user">Siege: {{match[7]}}</div> 
         </div> 
        </div> 

       </div> 
      </div> 
     </div> 
    </div> 
+0

请不要使用角标记角1.xx相关questions.Its具体到角2.x以上。 –

+0

@VikhyathMaiya好的,谢谢你的提示;) – jglom

回答

0

我不太明白你的最终目标,但也许您正在寻找这样的:

<!-- pass your element into focus() handler.--> 
<div class="col-md-1 result-input-wrp card-plan-result"> 
    <div class="quantity"> 
     <input type="tel" ng-model="model" ng-focus="focus(match[9])" ng-blur="blur()" maxlength="2" min="1" max="9" step="1" ng-value="'{{ match[9] }}'" title="result"> 
    </div> 
</div> 
// and in scope 
$scope.focus = function (matchedElement) { 
    console.log('focused', matchedElement); 
}; 

快速更新基于意见

它,因为它们都使用相同的NG-模型=“模式” 给他们一个不同的名称...

e.g ng-model="team_1" and ng-model="team_2". 

另外请注意,这两个NG-模型和NG - 值设置和修改输入的值

+0

这就是它!谢谢,它几乎工作。我现在唯一的问题是当我用一个数字填充输入时,对面的团队获得相同的值。例如:Team1(输入)VS Team2(输入)....我用1填充Team1输入,Team2输入也输入1。 – jglom

+0

更新后职位 –

+0

当然.....感谢:D – jglom

相关问题