Add items Ionic

0

I need the values to change by clicking the + and - buttons, as in the image.

I've taken an example in Plunker ( link ) and I'm trying to adapt to what I need, but I'm not having success. Could someone give me some tips? Here's what I have so far:

    $scope.formData = [];

    $scope.products = [{
        'id': '1',
        name: 'Festa do Cabide'
    }, {
        'id': '2',
        name: 'Balada do Natal'
    }, {
        'id': '3',
        name: 'Almôndegas Radiotivas'
    }];

    $scope.changeQuantity = function (productId, quantity) {
        var newItem = true;
        angular.forEach($scope.formData, function (value, index) {
            console.log(value);
            console.log(index);
            if (value.product_id === productId) {
            //remove if quantity 0 or null
                if (quantity === 0 || quantity === null) {
                    $scope.formData.splice(index, 1);
                }else {
                    $scope.formData[index].quantity = quantity;
                }
                newItem = false;
            }
        });
        if (newItem) {
            $scope.formData.push({product_id: productId, quantity: quantity});
        }
    };
            <pre>{{ formData }}</pre>
            <ul ng-repeat="product in products">
              <li>{{ product.name }}</li>
              <label for="">Quantity: </label>

              <input type="number" ng-model="quantity" placeholder="product_{{product.id}}" value="" style="border: thin solid black">
              <i class="icon ion-ios-minus-outline" mouse-down-up ng-click="clickQuantity(product.id, quantity)"></i>
              <i class="icon ion-ios-plus-outline" mouse-down-up ng-click="changeQuantity(product.id, quantity)"></i>
    
asked by anonymous 13.03.2017 / 16:41

1 answer

0

Another developer helped me and solved it as follows:

    $scope.ticketPlus = function(ticketIndex, itemIndex) {        
        $scope.tickets[ticketIndex]['items'][itemIndex]['quantity'] ++;
        console.log($scope.tickets);
    }

    $scope.ticketMinus = function(ticketIndex, itemIndex) {
        if(!$scope.tickets[ticketIndex]['items'][itemIndex]['quantity'] == 0) {
            $scope.tickets[ticketIndex]['items'][itemIndex]['quantity'] --;
        }
 
    }
<div class="row text-center">
  <div class="col">
    <i class="icon ion-ios-minus-outline" ng-click="ticketMinus(ticketIndex, itemIndex)"></i>
  </div>
  <div class="col">
    <input type="number" ng-model="item.quantity" placeholder="0">
  <div class="col">
    <i class="icon ion-ios-plus-outline" ng-click="ticketPlus(ticketIndex, itemIndex)"></i>
  </div>
</div>
    
13.03.2017 / 18:41