user2737948 user2737948 - 27 days ago 23
JSON Question

Trigger ng-show when json data changed

I'm trying to hide the upload button and display a new edit button when the user uploads a file. I'm using angular-file-upload and md-data-table libraries. I use the test function in order to save the row that was clicked and then after the file is uploaded I change the uploaded value inside the json. It changed the value to true in the user_doc json object but it doesnt hide the buttons in the html

This is a snip from my 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>




Snippet from the controller

$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;

Answer Source

Just replace uploaded values mentioned inside ng-repeat by 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>