0

您好我想创建有状态的情态,使用的UI路由器和用户界面的自举,我有模态开成功就是这样,角度ui bootstrap模态打开状态,如何在控制器中关闭?

.state('static.login', { 
     url: '^/login', 
     onEnter: function($modal, $state, $stateParams) { 
      var modalInstance; 
      modalInstance = $modal.open({ 
       animation : false, 
       templateUrl : 'app/components/login/views/login.view.html', 
       controller : 'loginController', 
       size : 'lg' 
      }); 
      return modalInstance.result["finally"](function() { 
       return $state.go('^'); 
      }); 
     } 
     // templateUrl: 'app/components/login/views/login.view.html', 
     // controller: 'loginController' 
    }) 

但我挣扎着从我的LoginController关闭模式,我认为这将是运行$modal.dismiss('cancel')的情况下,一个简单的,但我得到告诉解雇是未定义功能,做我需要做别的东西能够从我的控制器关闭我的模式?

也当过我浏览到/登录首页显示模式之下,这将是巨大的,如果我把它下面的当前页面,这可能吗?

+0

一种方式是通过服务来打开它,并与控制器共享服务。将modalInstance对象存储在服务中 – charlietfl

+0

将其作为激活功能在控制器中打开。并且您可以轻松关闭它。 –

回答

0

一旦你打开一个模态,内部模态控制器,即loginController,你可以看到$modalInstance服务,它将抓住模态实例。

在那里,你可以注入,并使用内部loginController

$modalInstance服务以及关闭弹出你可以关闭方法在$modalInstance

app.controller('loginController', function($modalInstance){ 

    //..other controller code which you already had 

    //for closing popup do below 
    $modalInstance.close(); 

});