Ionic show select with options on button action

2019-07-11 08:11发布

问题:

I want to show options while pressing the button not to show dropdown box. For the reference of select. But when I try to implement it gives me dropdown box. I don't want to show it. I want to show options.

回答1:

Hi This is worked for me based upon your requirement, Please have a look:
1.In your index.html add a button with a method as

<ion-content ng-controller="ExampleCtrl">
      <button class="button button-bar button-positive" ng-click="showSelect()">Options</button>
      </ion-content>

2.In your app.js file write the controller code with function as:

.controller('ExampleCtrl', ['$scope', '$ionicPopup',function($scope,$ionicPopup) {
  $scope.values=['1','2','3','4'];
  $scope.showSelect = function(){
    $ionicPopup.alert({
      title:'select an option',
      templateUrl:'test.html'
    });
  }

}])

3.last and final step create a test.html file in your project and paste the code as:

<ion-view view-title="select">
  <ion-content ng-controller="ExampleCtrl">
    <ion-list ng-repeat="item in values">
      <ion-item>
        {{item}}
      </ion-item>
    </ion-list>
  </ion-content>
</ion-view> 

Having any queries,Please reply..