2016-01-11 26 views
0

我第一次使用Angular JS進行開發,我創建了以下引導模式,其中有一些內容和輸入的表格。這裏是代碼:如何清除引導模態內容的角度(不使用jQuery)?

<div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
      <h4>User Menu</h4> 
     </div> 
     <div class="modal-body"> 
      <div class="tablecontainer"> 
       <table class="table table-striped table-hover table-condensed"> 
        <colgroup> 
         <col class="col-md-1"> 
         <col class="col-md-2"> 
         <col class="col-md-2"> 
         <col class="col-md-3"> 
         <col class="col-md-2"> 
         <col class="col-md-2"> 
        </colgroup> 
        <thead> 
         <tr> 
          <th>&nbsp;</th> 
          <th>Firstname</th> 
          <th>Lastname</th> 
          <th>Address</th> 
          <th>Attachment</th> 
          <th>Group</th> 
         </tr> 
        </thead> 
        <tbody> 
         <tr ng-repeat="user in users"> 
          <td> 
           <input type="checkbox" value="" ng-model="ctrl.checked[$index]" ng-disabled="ctrl.fileupload!==undefined" ng-change="ctrl.checkBox($index)" /> 
          </td> 
          <td>{{user.firstname}}</td> 
          <td> 
           <select class="form-control" ng-model="user.selectedAddress" ng-change="ctrl.checked[$index] = user.selectedAddress.destAddress" ng-options="o as o.destName for o in user.addresses"></select> 
          </td> 
          <td>{{user.selectedAddress.destAddress}}</td> 
          <td><input type = "text" class="customPart" 
        ng-model="ctrl.customText[$index]" /></td> 
         </tr> 
        </tbody> 
       </table> 
      </div> 
      [...] 
     </div> 

     <div class="modal-footer"> 
      <button type="button" class="btn btn-default btn-flat" data-dismiss="modal">Close</button> 
     </div> 
    </div> 
</div> 

什麼是清除引導模式重置用戶輸入的角度方式?

回答

1

您不需要重置界面來創建一個新的模型,您不會做相反的事情。您需要重置模型,然後您的用戶界面將被重置。

你可以編寫一個函數來重置你的users數組。例如:

function reset() { 

    for(var i = 0; i < users.length; i++) { 
     users[i].selectedAddress = null; 
    } 
} 
+0

您的解決方案讓我深入它,我發現'angular.copy'。你知道有什麼方法在'users'數組中使用'angular.copy'嗎?該副本似乎不適用於數組。我對嗎? – smartmouse