0

In AngularJS,I open a modal by calling a service from controller:

controller:

$scope.openDialog = function (row) { 
            myService.showDialog(id, dataDate).result.then(function (flag) {
                if (flag) {
                    //...
                }

            }); 
    };

myService:

this.showDialog = function (id, selectdate) {
            return wapPromptService.showDialog({
                templateUrl: 'dialog.html'
                controller: 'dialogCtrl',
                windowClass: 'sendmargin',
                size: 'lg',
                resolve: {
                    loadModule: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load({
                            files: [
                               
                            ]
                        });
                    }],
                    id: function () {
                        return id;
                    },
                    selectdate: function () {
                        return selectdate;
                    },
                   
                }
            });
        };

I would like to hide the modal when I redirect to other page, and when I come back to page, the dialog is still there (shows there).

But I could only find the way to close or dismiss it like (inject $uibModalInstance into dialogCtrl):

$uibModalInstance.close(true)

or

$uibModalInstance.dismiss('cancel')

How can I hide and show it again with its previous state?

A similar question:

How to hide/show same modal instance with AngularJS?

Ryan
  • 19,118
  • 10
  • 37
  • 53
  • You could save the state of the modal in a service (so that it wont be deleted on dialog close), listen to your router stateChange event, and if you get back to the page where the dialog is needed, AND you have the appropriate flag+data in the service, show the dialog again. – Nitsan Baleli Jul 22 '20 at 14:05
  • @Nitsan Baleli This is what I am doing now. How could I know I do not want these saved data when I refresh the page – Ryan Jul 23 '20 at 01:56
  • Im not entirely sure what you mean, if you want to persist data between page refresh you'd have to use something like local storage – Nitsan Baleli Jul 23 '20 at 10:52

0 Answers0