从控制器关闭角度引导模式窗口

时间:2022-06-07 03:06:21

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

我在我的模态窗口中有一个联系人表单。请求成功后,我想自动关闭模式。我用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?

如何在$http后关闭我的模式。后成功?

3 个解决方案

#1


3  

I got something for you

我有东西要给你

Use:- $modalStack

使用:modalStack美元

And then call $modalStack.dismissAll();

然后调用modalStack.dismissAll美元();

Simple plunker

简单的一美元

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

我在柱塞中使用了$timeout你可以在任何地方使用$http:-)

Doc

医生

#2


1  

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();

将模式设置为作用域上的变量,然后通过模板上的函数传递它,并调用modalvarname . dismis();

#3


-1  

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

对于我来说,使用$modalStack给了我注入错误,即使我将$modal和$modalStack作为依赖注入。以下工作:

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

#1


3  

I got something for you

我有东西要给你

Use:- $modalStack

使用:modalStack美元

And then call $modalStack.dismissAll();

然后调用modalStack.dismissAll美元();

Simple plunker

简单的一美元

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

我在柱塞中使用了$timeout你可以在任何地方使用$http:-)

Doc

医生

#2


1  

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();

将模式设置为作用域上的变量,然后通过模板上的函数传递它,并调用modalvarname . dismis();

#3


-1  

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

对于我来说,使用$modalStack给了我注入错误,即使我将$modal和$modalStack作为依赖注入。以下工作:

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