聚焦新的ng-repeat元素

时间:2015-08-31 02:39:44

标签: angularjs ng-repeat angularjs-ng-change

使用Angular,我希望用户能够输入主角度,然后(如果条目尚未存在)推送一个新的动作'进入' actions [module.id] .actions'数组,因此用ng-repeat创建一个新的输入,然后我想专注于那个新的输入。

我正在使用' addActionAction()'将新值添加到数组然后专注于新创建的输入,但似乎直到& addActionAction()'之后才实际创建输入。已完成运行,因此在我想要关注它时,输入不存在。有办法解决这个问题吗?

     <div ng-repeat="(key, action) in actions[module.id].actions" >
      <span class="action-profile">{A{action}A}</span>
      <input id="action-input-{A{module.id}A}-{A{key}A}"type="text" ng-model="action">
    </div>

      <!-- main input-->
      <input type="text" ng-model="$parent.newActionText" ng-change="addActionAction()">

功能:

$scope.addActionAction= function()
  {
    if($scope.actions[$scope.selectedId].actions.indexOf($scope.newActionText) == -1)
    {
      $scope.actions[$scope.selectedId].actions.push($scope.newActionText);
      $scope.newActionText="";
      document.getElementById("action-input-"+$scope.selectedId+"-"+String(parseInt($scope.actions[$scope.selectedId].actions.length)-1)).focus();
    }

  };

0 个答案:

没有答案
相关问题