2017-05-03 60 views
0

我有一個彈出的離子,並有一個文本框和一個按鈕。我想按回車鍵並希望按鈕工作並關閉彈出窗口。林想知道如何在下面的這個彈出窗口中執行此操作。按Enter鍵提交與AngularJs的離子Popup

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 
         }) 
        } 
        } 
       ] 
     }); 
+0

可能的重複[提交表單按Enter與AngularJS](http://stackoverflow.com/questions/15417125/submit-form-on-pressing-enter-with-angularjs) – Pengyy

回答

0

我會建議你使用<form>並設置你的按鈕type="submit"

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

submitPopup功能,做任何你想要和關閉模式:

$scope.submitPopup = function() { 
    $http.get(...); 
    myPopup.close(); 
} 
+0

在哪裏添加它在彈出?因爲我不像普通方式那樣定義按鈕。 – birdcage

0

可能你已經過濾了按鈕事件。

如果(e.name = 「」) - >

爲$ http.get工作?