2

I have a contact form inside my modal window. After successful post request i want to close the modal automatically. I am using MEAN.JS

here is my controller

angular.module('core').controller('FormCtrl',['$scope','$http', function($scope,$http) { $scope.postMail = function (data) { $http.post('/mail', data). success(function(data, status, headers, config) { alert('success'); //close function....?? }). error(function(data, status, headers, config) { }); }; }]);//formController ends 

How can i close my modal after $http.post success?

7
  • Please read the docs that you are linking to. It clearly describes how to close a modal and even provides an example Commented Feb 13, 2015 at 11:13
  • Hey but it didn't provide how to close modal in controller :-P @rmuller Commented Feb 13, 2015 at 11:15
  • eh? there is clearly a close method inside a controller in that javascript Commented Feb 13, 2015 at 11:19
  • I tried $modalInstance.dismiss('cancel'); but it saying .dismiss in undefined. Commented Feb 13, 2015 at 11:25
  • That close method is inside the controller of $modalInstance not in the main controller that is creating the modal:-P Commented Feb 13, 2015 at 11:25

3 Answers 3

5

I got something for you

Use:- $modalStack

And then call $modalStack.dismissAll();

Simple plunker

I used $timeout in plunkler you can use it anywhere like $http :-)

Doc

Sign up to request clarification or add additional context in comments.

2 Comments

Worked smoothly... :)
Great have fun with modal;:-)
0

As crude as it is...

Set the modal as a variable on the scope then just pass it through a function on the template and call modalVarName.dismiss();

1 Comment

Thank you for an answer. It would be beneficial to add a code snippet to illustrate it.
-2

For me using $modalStack gave me injection error even though I injected $modal and $modalStack as dependency. Following worked:

angular.element(document.querySelector('#modal')).modal('hide'); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.