2015-02-05 195 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 ']。值;

相關問題