0
I got the following form
which sits within a modal:
<form name="usuarioForm" novalidate="">
At the end of this form
I have a button where I pass the object that was filled into a function, and in that function I try to clear the form that way:
$scope.usuarioForm.$setPristine();
But I get that mistake:
Error: $Scope.usuarioForm is Undefined
Another thing I noticed, when I try to clear the object like this: $scope.usuario = "";
after saving the data nothing happens either. IE, gives the impression that this modal is not inside the controller.
I put this modal inside my page that has the controller: loginCtrl
thus:
<script id="my-modal.html" type="text/ng-template">
<ion-modal-view class="back">
<ion-header-bar class="bar-dark">
<h1 class="title">Novo Usuário</h1>
</ion-header-bar>
<ion-content >
<form name="usuarioForm" novalidate="">
...//Todo código da página
<button class="button button-block button-positive"
type="submit" ng-click="salvar(usuario)"
ng-disabled="usuarioForm.$invalid">
<i class="ion-checkmark"></i>
Cadastrar
</button>
</form>
</ion-content>
</ion-modal-view>
</script>
Controller:
$scope.salvar = function(usuario) {
usuarioAPI.saveUsuario(usuario).success(function(data) {
console.log("Salvar!");
delete $scope.usuario;
$scope.usuarioForm.$setPristine();
$scope.closeModal();
})
.error(function(response, status) {
console.log("erro " + status);
});
}
Modal opening code:
$ionicModal.fromTemplateUrl('my-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function() {
$scope.modal.show();
};
$scope.closeModal = function() {
$scope.modal.hide();
};
how is the code of your controller?
– Bruno Piovan
I will edit the question and put the code of the save function that is in the controller
– DiegoAugusto
Could you also include the modal opening code? I think it will be important to define the problem.
– Ricardo Rodrigues de Faria
I added in the question @Ricardorodriguesdefaria
– DiegoAugusto
@Techies dude, I couldn’t help you, it all seems okay, the form should have been assigned to Scope.
– Ricardo Rodrigues de Faria
Yes, ta strange in Angular works, another thing that is not working is also when I try to grab rum object, for example:
$scope.usuario.nome
of error– DiegoAugusto