0
I have the situation: in the table below, when I click on "edit", displays the form with the required fields (including with a new "cancel" button). So far everything is working well. The problem is that when saving, the form should disappear (ng-Hide) and present the normal data again. Just below there is an excerpt with JS. As far as I understand I’m not managing to change the "Editing" after saving.
Table with phones
<form name="telefoneEdit">
<table class="table table-hover">
<thead>
<tr>
<th width="30%">Telefone</th>
<th width="20%">Ramal</th>
<th width="40%">Descrição</th>
<th width="10%"></th>
</tr>
</thead>
<tbody ng-repeat="telefone in clienteCtrl.cliente.ClienteTelefone" ng-form="tel" ng-init="editing = false">
<tr ng-show="!editing">
<td>{{telefone.tel}}</td>
<td>{{telefone.ramal}}</td>
<td>{{telefone.descricao}}</td>
<td class="text-center">
<a ng-click="editing = true" class="btn btn-default btn-xs"><i class="icon-pencil2"></i></a>
</td>
</tr>
<tr ng-show="editing">
<td>
<div class="col-md-4">
<input ng-model="telefone.ddd" type="number" name="ddd" max="99" ng-maxlength="2" class="form-control input-sm"></input>
<label class="error" ng-show="tel.ddd.$invalid">Campo inválido</label>
<label class="error" ng-show="erros.ddd">{{erros.ddd[0]}}</label>
</div>
<div class="col-md-8">
<input type="number" name="telefone" ng-model="telefone.telefone" class="form-control input-sm" ng-minlength="8" required></input>
<label class="error" ng-show="tel.telefone.$invalid">Campo inválido</label>
</div>
</td>
<td>
<input ng-model="telefone.ramal" class="form-control input-sm"></input>
</td>
<td>
<input ng-model="telefone.descricao" class="form-control input-sm"></input>
</td>
<td class="text-center">
<button class="btn btn-default btn-xs" type="button" ng-click="editTelefone(telefone)"><i class="icon-disk"></i></button>
<a ng-click="editing = false" class="btn btn-default btn-xs"><i class="icon-close"></i></a>
</td>
<input type="hidden" ng-model="telefone.id" />
</tr>
</tbody>
</table>
</form>
Excerpt from the JS that should work
$scope.editTelefone = function(telefone) {
var erros = {};
var _data = {};
_data.ClienteTelefone = telefone;
self.editing = false;
$http
.post('api/cliente_telefones/edit.json',_data)
.success(function(data){
if(data.erros) {
$scope.erros = data.erros;
}
else {
self.telefone = telefone;
$scope.erros = false;
$scope.editing = false;
}
})
}
Everything works correctly, I just can’t hide the form again.
Illustrative images
You put the tag
angularjs-directives
, this JS code you posted is inside a Directive? or a controller?– celsomtrindade
Is in a controller
– Danilo Miguel
You were able to verify if you’re getting any feedback inside the
success
? If the result you expect is really coming?– celsomtrindade
@Celsomtrindade is all working correctly: the data is sent and saved in the database without problems. But $Scope.Editing = false is not reflecting any effect. This is the problem.
– Danilo Miguel