不要摧毁一个接近角度引导模式 [英] Don't destroy an Angular Bootstrap modal on close

查看:166
本文介绍了不要摧毁一个接近角度引导模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的角度引导来显示一个模态(一presented 这里 ),它完美的作品。然而,这种角延伸的默认行为是模态被重建(及其控制器的一个新实例将creatred)时,它被关闭,然后再次打开。

I am using Angular Bootstrap to display a Modal (the one presented here), which works perfectly. However, default behavior of this Angular extension is that the modal is reconstructed (and a new instance of its controller will be creatred) whenever it is closed and then opened again.

因为我有一些pretty先进的东西模态中的想法,我想模​​态,当它被关闭,只是被隐藏,因此,它的状态保持。我已经搜索了一下周围,但不幸的是找不到一个简单而有效的答案。

Since I have some pretty advanced stuff going on inside the Modal, I would like the modal to just be hidden when it is closed, so that its state remains. I have searched around a bit, but unfortunately could not find a simple and effective answer.

就躲在这将是一种选择,但这种遂将每当模式被关闭的情况发生,所以也当它关闭,因为背景被点击。我想同样的动画,当模式以正常的方式被打开。

Just hiding it would be an option, but this then has to happen whenever the modal is closed, so also when it closes because the backdrop is clicked. And I want the same animation as when the modal is opened in the normal way.

推荐答案

为什么不抽象模式状态变成自己的服务?这样,每当创建模态控制器,它使用服务来设置视图状态的初始化。

Why don't you abstract the modal state into its own service? That way, whenever the modal controller is created, it uses the service to setup the view state on initialisation.

例如。创建服务

.factory('ModalStateService', function(){
    var state = {
        someValue: 'something'
    };

    return {
        getState: function() { return state; }
    };
});

然后在你的控制器:

Then in your controller:

.controller('ModalCtrl', function($scope, ModalStateService){
    $scope.viewState = ModalStateService.getState();
});

然后在例如您的情态的内容视图:

Then in your modal content view for example:

<span>{{viewState.someValue}}</span>

如果你当时设置 someValue中你的语气里,说通过输入,服务状态将被更新。然后,当你创建和销毁你的模式,国家将继续存在。

If you were then to set someValue inside your modal, say through an input, the service state would be updated. Then when you create and destroy your modal, the state will persist.

这篇关于不要摧毁一个接近角度引导模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆