清除ng-repeat创建的输入字段

时间:2014-07-25 09:04:34

标签: angularjs

我正在进行ng-repeat并根据动态nr的玩家创建输入字段。

<div class="row">
      <div ng-repeat="p in players" class="col-sm-3 col-md-3 col-lg-3">
        <h2>{{p.name}}</h2>

        <div ng-repeat="po in p.points">
          <p class=""><span>Round: {{po.Round}}</span> {{po.Point}}p </p>
        </div>
        <p>Total: {{p.total}}</p>
        <p ng-if="p.gameover == true">GAME OVER</p>
        <form role="form">
          <div class="form-group">
            <label for="newpoint$index"></label>
            <input type="number" class="form-control" id="newpoint$index" ng-model="p.newpoint" ng-if="p.gameover == false" placeholder="Enter points">
            <button ng-click="updatePoint(p.id, p.newpoint)" ng-if="p.gameover == false" class="btn btn-primary btn-lg btn-block">+</button>
          </div>
        </form>

      </div>
</div>

这是updatePoint函数:

$scope.updatePoint = function (playerid, point) {
  var currentRound = $scope.players[playerid].points.length + 1;
    var pointObjToPush = {Round: currentRound, Point: point};
    $scope.players[playerid].points.push(pointObjToPush);
    $scope.players[playerid].total += point;
    if ($scope.players[playerid].total >= 200) {
        $scope.players[playerid].gameover = true;
    }
};

现在,我的问题是:每次用户向玩家添加一个点时,我都希望清除该输入字段,但我不知道如何使用angular来达到该spicifik输入字段。我可以用jquery做到这一点,但我宁愿用角度来做,如果可能的话。我想我应该在创建的输入字段上添加某种形式的指令,并从updatePoint函数触发它以清除字段,但我不知道如何完成。

编辑: 这是plunker我在

上工作

0 个答案:

没有答案