Reputation: 3364
I am having problem with resetting signup modal form fields.
For example, I have called a custom resetForm function when the user click modal close button and after getting $http request.
$scope.resetForm = function () {
$scope.successMessage = "";
$scope.message = "";
$scope.FPEmail = "";
$scope.forgotForm.$setPristine();
};
But the bootstrap modals have property of getting close by clicking outside the modal body. In this case, I am not able to resetForm. I have tried to resolve it by putting ng-click on the button by which I am opening the modal. But this button is situated outside the controller and I don't know how to reset the form from outside the controller.
Upvotes: 1
Views: 996
Reputation: 211
you can use little code of jQuery in controller
$('#id').val(' ')
Worked for Me..
Upvotes: 0
Reputation: 552
To use scope in this instance, you'll need the buttons ng-click within the ng-controller that it relates to. The alternative is using JavaScript if you cant do this.
Have a look at a question I asked yesterday :) it may be helpful if you're using angular-UI
AngularJS $modalInstance - Can i do this in one controller?
Upvotes: 1
Reputation: 193261
Angular BootstrapUI $modal
service call returns an object with property result
which is "a promise that is resolved when a modal is closed and rejected when a modal is dismissed". Closing modal by clicking outside of the popup is considered rejection of this promise. It means that in your case you need to call resetForm
in reject callback of the promise. For example:
$modal.open({
template: 'form.html',
controller: 'formController'
})
.result.then(function() {
alert('resolved')
}, function() {
$scope.resetForm();
});
Upvotes: 1