title: While Loop with AngularJS?
body: <p>I'm trying to mimic the while loop of plain Javascript in AngularJS. I simply want to call the createPlant() method x number of times according to the value of the quantity input, when the "add" button is clicked, as follows (it adds to an array 'plants'):</p>
  
  <pre><code>$("#add").on("click", function() {
      var i = 0;
      while (i &lt; $("#pQuantity").val()) {
          createPlant();
          i += 1;
      };
  </code></pre>
  
  <p>In Angular I have:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;button ng-click="addPlant()" type="button"&gt;Add&lt;/button&gt;
  </code></pre>
  
  <p>And I'm not sure how the script would look but this is what I wrongly put:</p>
  
  <p><strong>JS</strong></p>
  
  <pre><code>var i = 0;
  while (i &lt; $("#pQuantity").val()) {
      $scope.addPlant = function() {
          var plant = {name: $("#pVariety").val()};
          $scope.plants.unshift(plant);
      };
      i += 1;
  };
  </code></pre>