0

I have a popup in ionic and have one textfield and one button in it. I want to press enter and want button to work and close the popup. Im wondering how to perform this action within this popup below.

var myPopup = $ionicPopup.show({
            template: '<input type = "text" ng-model = "data.model"><br> '
            , title: 'Name'
            , scope: $scope
            , buttons: [
                {
                    text: 'Cancel'
                }, {
                    text: '<b>Search</b>'
                    , type: 'button-positive'
                    , onTap: function (e) {
                        $ionicLoading.show();
                        $http.get(HTTPService.getHttpText() + 'Persons/' + $scope.data.model).then(function (resp) {
                            console.log('Success', resp);
                            $ionicLoading.hide();
                        }, function (err) {
                            $ionicLoading.hide();
                            console.error('ERR', err);
                            // err.status will contain the status code
                        })
                    }
                    }
                ]
        });
birdcage
  • 2,638
  • 4
  • 35
  • 58
  • Possible duplicate of [Submit form on pressing Enter with AngularJS](http://stackoverflow.com/questions/15417125/submit-form-on-pressing-enter-with-angularjs) – Pengyy May 03 '17 at 07:40

2 Answers2

1

I would suggest you to use a <form> and to set your button type="submit":

<form ng-submit="submitPopup()">
    <button type="submit">Close</button>
</form>

In the submitPopup function, do whatever you want and close the modal:

$scope.submitPopup = function() {
    $http.get( ... );
    myPopup.close();
}
Mistalis
  • 17,793
  • 13
  • 73
  • 97
0

Probably you have filter the button event.

if(e.name="") -->

is $http.get working?