如何淡化父$ mdDialog?

时间:2017-01-11 15:07:57

标签: angularjs angular-material

我在父控制器中使用父$ mdDialog和child $ mdDialog。

主控制器

function addMembers( ev) {
        $mdDialog.show({
            templateUrl: 'app/add-members.html',
            parent: angular.element(document.body),
            controller: 'ChildController',
            controllerAs: 'vm',
            targetEvent: ev,
            clickOutsideToClose: true,
            preserveScope: true,
            fullscreen: vm.isCustomFullscreen, // Only for -xs, -sm breakpoints.
            autoWrap: true,
            skipHide: true
        })
    }

在父控制器内:

public partial class Form1 : Form
    {
        Form frm1 = new Form();
        int i;
        private System.Threading.Timer t;
        //If the problem is garbage collecting then the line above is very important.
        public Form1()
        {
            InitializeComponent();
            var autoEvent = new AutoResetEvent(false);
            var stateTimer = new System.Threading.Timer(CallToChildThread,
                                   autoEvent, 1000, 250);
        }
    private void CallToChildThread(object state)
    {
        i++;
        //Updating value here, update in other timer (this is to avoid crossthreadEx)   
    }

    private void button1_Click(object sender, EventArgs e)
    {
        frm1.ShowDialog();
        //Label keeps updating!
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        label1.Text = i.ToString();
    }
}

当我打开它的孩子时,我想淡化父对话窗口。有没有办法做到这一点?

2 个答案:

答案 0 :(得分:1)

请尝试以下方法。这个想法是当用户点击父对话框上的ok时打开子对话框。 并且在取消时不做任何事情。

$scope.openItemEdit = function (item, ev) {
        $mdDialog.show({
            templateUrl: 'app/item-config.tmpl.html',
            parent: angular.element(document.body),
            controller: 'ParentController',
            controllerAs: 'vm',
            targetEvent: ev,
            clickOutsideToClose: true,
            fullscreen: vm.isCustomFullscreen, // Only for -xs, -sm breakpoints.
            locals: {item: item}
        })
            .then(function () {
                $scope.status = 'ok';

                    $mdDialog.show({
                                templateUrl: 'app/add-members.html',
                                parent: angular.element(document.body),
                                controller: 'ChildController',
                                controllerAs: 'vm',
                                targetEvent: ev,
                                clickOutsideToClose: true,
                                preserveScope: true,
                                fullscreen: vm.isCustomFullscreen, 
                                autoWrap: true,
                                skipHide: true
                            })
            }, function () {
                $scope.status = 'cancel';
            });
    };

答案 1 :(得分:0)

我找到了解决方案:

在子$ mdDialog中。有一个名为:' parent' - 我们在哪个DOM附加对话框窗口。所以我稍微改了一下,现在父对话框窗口消失了。

function addMembers( ev) {
        $mdDialog.show({
            templateUrl: 'appadd-members.html',
            parent: angular.element(document.getElementById('ParentDialog')),
            controller: 'AddMembersController',
            controllerAs: 'vm',
            targetEvent: ev,
            clickOutsideToClose: true,
            preserveScope: true,
            fullscreen: vm.isCustomFullscreen, // Only for -xs, -sm breakpoints.
            autoWrap: true,
            skipHide: true
        })
    }