2017-09-22 81 views
0

我試圖隱藏上傳按鈕,並在用戶上傳文件時顯示新的編輯按鈕。我正在使用angular-file-upload和md-data-table庫。我使用測試功能來保存被點擊的行,然後在文件上傳後,我更改json中的上傳值。它改變了價值真正在user_doc JSON對象,但它不隱藏在HTML當json數據發生變化時觸發ng顯示

按鈕這是我的HTML

<md-table-container> 
    <table md-table multiple ng-model="selected"> 
     <thead md-head md-order="query.order"> 
      <tr md-row> 
       <th md-column><span class="settings-header">Tipo de documento</span></th> 
        <th md-column><span class="settings-header actions">Acciones</span></th> 
      </tr> 
     </thead> 
     <tbody md-body> 
      <tr md-row md-select-id="id" md-auto-select ng-repeat="row in options"> 

       <td md-cell>{{row.name}}</td> 
       <td md-cell class="buttons-cell" ng-show="!uploaded"> 
       <div ng-if="uploader"> 
        <label for="key" class="md-button profile-upload" ng-click="test(row)" ng-if="!uploaded"><i class="material-icons">file_upload</i></label> 
       <!-- <label for="key" class="md-button profile-upload" ng-click="test(row)" ng-if="uploaded"><i class="material-icons">PERP</i></label> --> 
        <input class="ng-hide" id="key" type="file" nv-file-select uploader="uploader" ng-if="!uploaded"> 
       </div> 
      </td> 
     </tr> 
    </tbody> 
</table> 

片段剪斷從控制器

$scope.uploader = new FileUploader(); 
let row_selection; 

$scope.test = function(row,fileItem){ 
    console.log(row.id); 
    row_selection = row; 
} 
$scope.uploader.onAfterAddingFile = function(fileItem) { 
    if(fileItem.file.type === 'image/png' || fileItem.file.type === 'image/jpeg'){ 
     row_selection.uploaded = true; 
    }else{ 
     showAlert(); 
    } 
} 
$scope.user_doc = { 
    documents: { 
     options: [ 
      {"id":"01","name":"INE","uploaded":false}, 
      {"id":"02","name":"Comprobante de domicilio","uploaded":false}, 
      {"id":"03","name":"CURP","uploaded":false} 
     ] 
    } 
}; 
$scope.options = $scope.user_doc.documents.options; 

回答

1

只需將uploaded中提到的值內ng-repeat提到row.uploaded

<tr md-row md-select-id="id" md-auto-select ng-repeat="row in options">  
       <td md-cell>{{row.name}}</td> 
       <td md-cell class="buttons-cell" ng-show="!row.uploaded"> 
       <div ng-if="uploader"> 
        <label for="key" class="md-button profile-upload" ng-click="test(row)" ng-if="!row.uploaded"><i class="material-icons">file_upload</i></label> 
        <input class="ng-hide" id="key" type="file" nv-file-select uploader="uploader" ng-if="!row.uploaded"> 
       </div> 
      </td> 
     </tr> 
相關問題