2015-02-05 118 views
1

我正在使用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> 
+0

这可能会帮助你发布你的东西。 – 2015-02-05 18:09:09

+0

你如何打开模式? – PSL 2015-02-05 18:15:28

+0

@PSL,'ui-turn-on =“modal”'在按钮中。 micafe有一个好主意。当按钮被点击时,我可以在$ scope上设置一个变量。思考? – 2015-02-05 18:16:17

回答

1
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. 
1

可以编写一个HTML标记(项目)与属性值和读出的值

变种ID = item.attributes ['数据-ID ']。值;

相关问题