Pass id in a modal ionic Framework v1

0

hello good afternoon I find the following problem I have the following list that is loaded with a json object, which to each element I have attached a button to edit and remove

<div class="item item-divider bar bar-dark" >Listado de Pedido</div>
     <body>
   <form>
     <div class="item item-body">



          <ion-item ng-repeat="pedido in pedido">

     <h2>N°{{pedido.id_menu}}  Fecha:{{pedido.fecha}}</h2>
     <p>{{pedido.proveedor}}</p>
     <p>{{pedido.comida}}</p>
     <p>{{pedido.postre}}</p>
     <p>{{pedido.precio}}</p>
          <a class="button button-small button-assertive ion-trash-a" ng-click="BorrarPedido(pedido.id_menu)"> Eliminar</a>
          <a class="button button-small button-positive ion-edit" ng-click="openModal (pedido.id_menu)"> Editar</a>
           </ion-item>

        </ion-list>
     </form>
   </body>

and I assigned a modal so that once I selected the one I want to edit, I would have said modal with the data to be edited

<script id="my-modal.html" type="text/ng-template">
  <ion-modal-view>
     <ion-header-bar>

            <h1 class="title">Editar Pedido</h1>
            <button class="button button-icon   ion-close-circled" ng-click="modal.hide()">
            </button>
          </div>
        </ion-header-bar>
       <ion-content ng-repeat="pedido in pedido"> 
                    <div class="list">

                      <label class="item item-input">
                        <span class="input-label" ng-model="pedido.id_menu">Nro :{{pedido.id_menu }}
                      </label>
                      <label class="item item-input">
                        <span class="input-label" ng-model="pedido.fecha">Fecha: {{pedido.fecha}} </span>
                      </label>
                        <label class="item item-input">
                        <span class="input-label">Proveedor :</span>
                            <input type="text"  ng-model="pedido.proveedor">

                        </label>
                        <label class="item item-input">
                        <span class="input-label">Comida :</span>
                            <input type="text"  ng-model="pedido.comida">
                        </label>
                       <label class="item item-input">
                        <span class="input-label">Postre :</span>
                            <input type="text" ng-model="pedido.postre">
                        </label>
                       <label class="item item-input">
                        <span class="input-label">Precio :</span>
                            <input type="text"  ng-model="pedido.precio">
                        </label>
                        </div>
                    <button class="button button-positive button-block" ng-click="Editar(pedido,id_menu)">
                            Guardar
                        </button>



  </ion-modal-view>

and the next driver

.controller('MostrarPedidoCtrl',function($scope,$http,$state,$ionicPopup,$ionicModal){

$ionicModal.fromTemplateUrl('my-modal.html', {
    scope: $scope,
    animation: 'slide-in-up'

  }).then(function(modal) {
    $scope.modal = modal;
  });
   $scope.openModal = function(id_menu) {
    $scope.modal.show();
  };
  $scope.closeModal = function() {

    $scope.modal.hide();
  }

The issue is that when I select the modal modality, the modal one more than once loads the chosen one and does not let me modify it, please give me a help of how it would be the correct way to pass the id, I need to solve it from thank you very much.

    
asked by Sebastian Balmaceda 20.06.2017 в 17:34
source

1 answer

0

You can do it in the following way

$scope.openModal = function(id_menu) {
    $scope.id_menu = id_menu;
    $scope.modal.show();
};

To your modality you are already passing the father $scope therefore you can access its values from the modal.

    
answered by 20.06.2017 в 18:16