使用Angular中继器的多个输入的警报输入值

时间:2016-08-13 00:14:42

标签: javascript jquery html css angularjs

我正在使用Angular允许我根据需要创建尽可能多的输入,但我希望有一个简单的警报来显示输入的值。如果我没有使用重复,但是在重复之后,我能够获得价值。

<div ng-controller="MainCtrl">
  <form id="quickPick-form1" class="list" ng-submit="submit()" >
      <fieldset  data-ng-repeat="choice in choices" class="clearfix">
          <input type="text" placeholder="Item" class="pull-left" ng-model="item">
          <button class="remove pull-left" ng-show="$last" ng-click="removeChoice()">X</button>
      </fieldset>
      <button id="quickPick-button1" style="font-weight:600;font-style:italic;" class="addfields button button-calm button-block button-outline " ng-click="addNewChoice()">Tap me to add an item!</button>
      <div class="spacer" style="width: 300px; height: 40px;"></div>
      <p>Have enough items added? Click Randomize</p>
      <button ng-click="showChoice()" id="quickPick-button2" class=" button button-calm button-block ">Randomize</button>
      <div class="spacer" style="width: 300px; height: 20px;"></div>   
  </form>
</div>
<script>
.controller('MainCtrl', function($scope) {
  $scope.choices = [{id: 'choice1'}, {id: 'choice2'}];

  $scope.addNewChoice = function() {
  var newItemNo = $scope.choices.length+1;
    $scope.choices.push({'id':'choice'+newItemNo});
  };

  $scope.removeChoice = function() {
    var lastItem = $scope.choices.length-1;
    $scope.choices.splice(lastItem);
  };

  $scope.item = null;
  $scope.showChoice = function(){
    alert($scope.item);
  };

});
</script>

1 个答案:

答案 0 :(得分:0)

试试这个

$scope.showChoice = function(){
    alert($scope.choices.split(" /n"));
};

item不在您的范围内。您的范围内只有choices[]