Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to close popup from directive. #854

Closed
piernik opened this issue Mar 20, 2014 · 12 comments
Closed

Add possibility to close popup from directive. #854

piernik opened this issue Mar 20, 2014 · 12 comments
Assignees
Milestone

Comments

@piernik
Copy link

piernik commented Mar 20, 2014

You need to add possibility to close popup from code (not just buttons).

I'll use dangeross' example: http://codepen.io/dangeross/pen/wvAjJ/2
Open modal and then Add popup.
Should close popup after clicking option. Now I have to make two taps.

@ajoslin
Copy link
Contributor

ajoslin commented Mar 20, 2014

Possibility: Change popup API a bit, creating our own 'then' and also adding a close function.

var pop = $ionicPopup.show(...)
pop.then(function(response) {
});
$scope.closePopEarly = function() {
  pop.close();
};

@piernik
Copy link
Author

piernik commented Mar 20, 2014

That was fast:) Thanks I'll try.. when it will be ready ;)

@ajoslin
Copy link
Contributor

ajoslin commented Mar 20, 2014

It isn't implemented yet, it's an idea for implementing what you want though.

@mlynch mlynch self-assigned this Mar 20, 2014
@mlynch mlynch added this to the 1.0.0-beta.2 milestone Mar 20, 2014
@mlynch
Copy link
Contributor

mlynch commented Mar 20, 2014

I'll take a look at this one. Thanks Andy, good idea

@mlynch mlynch closed this as completed in dc2b24e Mar 20, 2014
@mlynch
Copy link
Contributor

mlynch commented Mar 20, 2014

Okay, took a slightly different approach for now:

$ionicPopup.show(...)
.then(function(response) {
}, function(err) {},
function(popup) {
});

You'll get the constructed popup in the notify function of the promise.

We should probably revisit this API later.

@stefanKuijers
Copy link

Hey guys,

First of all: Awesome job on the Ionic project. It's really great :D

I'm trying to close the popup but with no success. Here's what I tried:

var popup = $ionicPopup.show({
               templateUrl: 'view/dialog/med_reminder.html',
               title: "Title",
               scope: $scope,
               buttons: [
                  { text: 'ready',  onTap: function(e) { return true; } }
               ]
            }).then(function(response) {
                  $scope.handle_user_response(response);
            });

popup.close(true); // returns undefined is not a function
$ionicPopup.show({
              templateUrl: 'view/dialog/med_reminder.html',
              title: 'Enter Wi-Fi Password',
              subTitle: 'Please use normal things',
              scope: self.root_scope,
              buttons: [
                { text: 'Cancel', onTap: function(e) { return false; } },
                {
                  text: '<b>Save</b>',
                  type: 'button-positive',
                  onTap: function(e) {
                    return true;
                  }
                },
              ]
            }).then(function(res) {
              console.log('Tapped!', res);
            }, function(err) {
              console.log('Err:', err);
            }, function(popup) {
              // If you need to access the popup directly, do it in the notify method
              // This is also where you can programatically close the popup:
              popup.close();
            });

Here the last function where the popup.close() is. Is never fired.

Am I missing something or has this function been removed from the new nightlies?

Thanks in advance

@stefanKuijers
Copy link

PS: tried last beta (Cadnium Camel) as well with same results

@ajoslin
Copy link
Contributor

ajoslin commented May 15, 2014

You can't use .then on the popup object we give back to you, or it will return a new promise without the close method on it.

This is how it should be done:

var popup = $ionicPopup.show(..);
popup.then(...);
popup.close();

@ajoslin
Copy link
Contributor

ajoslin commented May 15, 2014

This should probably be clarified more in the docs.

@stefanKuijers
Copy link

@ajoslin thanks man! That fixed it.
It's certainly clear now :)

@jdnichollsc
Copy link

Close only works with $ionicPopup.alert :(

@onderceylan
Copy link

I wanted to close all the popups before leaving the screen. This is how I did it.

export class PopupService {

        public popups: ionic.popup.IonicPopupPromise[] = [];

        constructor(public $ionicPopup: ionic.popup.IonicPopupService,
                    public $rootScope: ng.IRootScopeService) {

            $rootScope.$on('$ionicView.beforeLeave', () => {
                this.hideAllPopups();
            });
        }

        public show(object: ionic.popup.IonicPopupFullOptions): ionic.popup.IonicPopupPromise {
            let newPopup: ionic.popup.IonicPopupPromise = this.$ionicPopup.show(object);
            this.popups.push(newPopup);
            return newPopup;
        }

        public hideAllPopups(): void {
            this.popups.forEach((popup: ionic.popup.IonicPopupPromise) => {
                popup.close();
            });

            this.popups = [];
        }
    }

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants