Add and edit item form same ionic modal form


#1

Hi, im using ionicModal to push items to an array, using ng-submit to push the object to this array, can somebody please post an example of how to use the same form for edit a clicked item in the list?

I can’t understand how to pass the list item instance to the form

$ionicModal.fromTemplateUrl('templates/add-item-modal.html', {  
    scope: $scope,
    animation: 'slide-in-up',
    focusFirstInput: true
  }).then(function (modal) {
    $scope.modal = modal;
  });

    <ion-modal-view>
  <ion-header-bar>
    <h1 class="title">Aggiungi</h1>
  </ion-header-bar>
  <ion-content class="padding">
  <form ng-submit="addItem()">
    <div class="list list-inset">
      <label class="item item-input">
        <input placeholder="Prodotto" ng-model="name" name="name" type="text">
      </label>
      <button class="button button-block button-positive activated">
        Submit
      </button>
    </div>
  </form>
  </ion-content>
</ion-modal-view>

#2

Did you ever got it resolved?


#3

Hi, i managed it this way. create a function that accept an item as agrument and bind it to scope if exist( used a edit button) or create a new one (clicked on new) then open the modal

    $scope.openModal = function(item) {
      $scope.itemInForm = item || {
        important: false,
       completed: false
     };
    $scope.modal.show();
  };

and in the form (inside the modal) i bind to itemInForm

<input ng-required="true" placeholder="Product" ng-model="itemInForm.name" name="name" type="text">

on your edit button

<ion-option-button class="button-energized" ng-click="openModal(item)">


#4

Thank you!!! her solution solved my problem too. :laughing: