我正在使用Mobile Angular UI,无法弄清楚如何将值传递给模式。

//按钮

此按钮在ng-repeat="item in vm.items"内,需要以某种方式将item传递给模式。

<button class="btn btn-danger pull-right" ui-turn-on="modal">Remove</button>


//模态
    

  <div class="modal scrollable-content section" ui-if='modal' ui-state='modal'>
    <div class="modal-backdrop in"></div>
    <div class="modal-dialog">
      <div class="modal-content">
        <form role="form" name="note" autocomplete="off">
        <div class="modal-header">
          <button class="close"
                  ui-turn-off="modal">&times;</button>
          <h4 class="modal-title">Are you sure?</h4>
        </div>

        <div class="modal-body">
          <p>Are you sure you'd like to remove this item?</p>
        </div>
        <div class="modal-footer">
          <button ui-turn-off="modal" class="btn btn-default">Cancel</button>
          <button type="submit" ng-click="vm.remove(item); Ui.turnOff('modal')" class="btn btn-primary">Remove</button>
        </div>
        </form>
      </div>
    </div>
  </div>

</div>

最佳答案

 on button click, you also call a function like

 <button class="btn btn-danger pull-right" ui-turn-on="modal"
 ng-click="setItemID(item.itemID)">Remove</button>

 And then create the setItemID(itemID) function into the angularjs controller
 and put the itemID into a scope variable.

 When user will click on the remove button, the setItemID function will be
 called and the itemId will be assigned into the scope. Now at the time when
 user click "Yes i want to remove this item", then use that defined itemID.
 Hope you get your solution. If still have any problem then lets comment.

09-19 22:38