Currently I'm stuck on a select input field. In the project was used this code:
<select ng-init="crtController.order.orders[$index].quantity = 0" ng-model="crtController.order.orders[$index].quantity" ng-options="value for value in crtController.quantity.values track by value" ng-change="crtController.quantity.check()"></select>
It was using this "quantity" variable:
this.quantity = {
values: [0,1,2,3,4,5,6,7,8,9,10],
decrease: function(index) {
if (vm.order.orders[index].quantity > 0) {
vm.order.orders[index].quantity--;
this.check();
}
},
increase: function(index) {
if (vm.order.orders[index].quantity < 10) {
vm.order.orders[index].quantity++;
this.check();
}
},
check: function() {
this.valid = false;
for (var i = 0; i < vm.order.orders.length; i++) {
if (vm.order.orders[i].quantity > 0) {
this.valid = true;
}
vm.order.orders[i].productId = vm.products[i].id;
}
vm.calculatePrice();
}
}
On the top of this select I've got a variable product.stock. Let's say this is 5. In that case I only want it to show 0,1,2,3,4,5 from the quantity array.
I already tried serveral things: 1. Adding a "where" clause. This didn't seem to work or I implemented it the wrong way of course. 2. Added a filter, not quite sure how this works using the value variable and the product.stock variable but I gave it a try. 3. I tried to change it so the repeat is on a option. This gave the possibility to "hide" options that should not be shown.
<select ng-init="crtController.order.orders[$index].quantity = 0" ng-model="crtController.order.orders[$index].quantity" ng-change="crtController.quantity.check()">
<option ng-repeat="value in crtController.quantity.values track by value" value="{{value}}" ng-hide="product.stock < value" ng-bind="value"></option>
</select>
but that didn't seem to work either as the first value of the selectbox is now empty. Beside that the buttons arround the select option:
<div class="input-group-addon hidden-xs"><a class="min" ng-click="crtController.quantity.decrease($index)">-</a></div>
didn't seem to work anymore. I also have visited a lot of similar Stackoverflow questions but still didn't find my solution. Questions such as: AngularJs conditional display for ng-options: I don't have this in my array, but didn't work just on a check of two variable.