Search code examples
javascripthtmlangularjshtml-selectangular-ngmodel

Javascript angularjs <select> has default value 0, when it should be 1


This is my html code:

      <table>
          <div ng-repeat="product in products" value="{{product}}">
             <div id="order_beacon" style="display: inline-flex; width: 100%;" class="row">
                 <span class="beacon_quantity">Quantity
                    <select id="beacon_count"  class="beacon_count"  ng-model="product.quantity">
                        <option ng-repeat="option in quantityOptions" value="{{option}}">{{option}}</option>
                    </select>
                 </span>
             </div>
          </div>
      </table>

in my JS I get back the list of products from the server, and even hardcoded all to have the quantity to 1.

  for (var j = 0; j < $scope.productsAll.length; j++) {
    $scope.productsAll[j].quantity = 1;
}

As you can see, my select tag, has the ng-model set as product.quantity. So shouldn't the default value be set to that?


Solution

  • <table>
              <div ng-repeat="product in products" value="{{product}}">
                 <div id="order_beacon" style="display: inline-flex; width: 100%;" class="row">
                     <span class="beacon_quantity">Quantity
                        <select id="beacon_count"  class="beacon_count"  ng-model="product.quantity" ng-options="b as b for b in quantityOptions">
    
                        </select>
                     </span>
                 </div>
              </div>
          </table>