Dismissing $ionicPopup

I am using ionicPopup for a two-factor login, which involves two successive popups, and I want to programmatically remove the ionicPopup. I am not using ionic’s built-in input field options because:

  1. I want to allow the user to submit the form via keyboard without having to dismiss the keyboard and tap the button on the popup.
  2. I want to specify the ‘type’ attribute - one is ‘email’ and another is ‘number.’

In order to do #1, I have a custom directive with which I can call my methods. See the on-keyup attribute in the template below. It calls the register method when the user hits the ‘Enter’ equivalent on the keyboard:

<script id="register" type="text/ng-template">
  <input type="text" ng-model="user.name"/>
  <input type="email" ng-model="user.email" on-keyup="register();" keys="[13]"/></script>

The code that triggers this prompt:

$ionicPopup.prompt({
        templateUrl:'register',
        scope:$scope,
        buttons: [
            { text: 'Register', onTap: $scope.register }
        ]
    });

If the user submits via tap, then the prompt goes away. If he hits ‘Enter,’ I can’t figure out how to programmatically remove the prompt. I’ve tried $ionicPopup.hide() and I tried seeing if the prompt function returned an object with a hide() method.

Any help would be greatly appreciated.

If you’re using the beta, you do it like this :

The nighty is different. If you need that sample, let me know.

Ok, I’ve given up on my original goal. But now I can’t get the popup to dismiss at all. I’m following the example in the docs (http://ionicframework.com/docs/api/service/$ionicPopup/) and I’m using beta 5.

$scope.ctrlRegister;
$scope.$on('onShowRegister',function(e,state){
    $scope.ctrlRegister = $ionicPopup.show({
        title:'Register'
        ,templateUrl: 'register'
        ,scope:$scope
        ,buttons: [
            {
                text: 'Next',
                type: 'button-dark',
                onTap: function(e) {
                    e.preventDefault();
                    goba.register(false,$scope.state.bSignIn);
                }
            }
        ]
    });
});
$scope.$on('onUserRegistered',function(){
    if ($scope.ctrlRegister)
        $scope.ctrlRegister.close();
});

And the ctrlRegister is there when I try to close it. It just doesn’t close.

Update: I tried calling ctrlRegister.close() twice and it went away. ??

Ok, final update. I have a complex set of rules with various popups - which means I was creating a popup and losing its reference.

Therefore, I created an array and pushed all popups created onto the array. When the view closes, I loop through the array and close any open popups (or instantiated

Open this post again, i have one question:

How i can make a simple custom popup like this to show on my entirely app and change some parameters according the situation (example: error, warning, info…), this popup i need to call from every where on the app.?

@Norwill
I think you should handle it with angular service.