I have built an Ionic2 app and I am currently trying to improve the UX. To do that, I received some feedback that made me think of whether there is a way of having a
<ion-select>
<ion-option>
</ion-option>
</ion-select>
which upon tapped on, would give me the output straight away and not wait for the user to press on the currently appearing 'OK'and 'CANCEL' buttons that the ionic action sheet(http://ionicframework.com/docs/v2/api/components/select/Select/) uses by default.
Any suggestions will be greatly appreciated! :)
EDIT:
As @sebaferrreras has suggested,
If the number of options exceed 6, it will use the alert interface even if action-sheet is passed.
So if you need to use more than 6 options, you are going to have to find a workaround as for the moment, this functionality is NOT listed under the Ionic2 docs.
Pass empty value :
It is working in my case.
I know this thread is 7 months old and the OP is probably long past this question but since the feature is yet to be added to ionic framework, I'm adding the workaround I came up with for other people's reference.
CSS PART
Intuitively the first thing you need to do is to add some sass/css to hide the unwanted buttons. I did that by passing a css class "remove-ok" to
selectOptions
for myion-select
element. (I'm only removing OK button but if someone needs to remove cancel button as well, that's an easy css modification).In component:
and in HTML:
And in
app.scss
add:SCRIPT PART
Now that the OK button is hidden, you will need to somehow close the alert view.
To invoke
click()
event on the hidden OK button is straightforward and intuitive but you'll soon find out that although it works perfectly onionic serve
, it won't work on an actual iOS device.The solution is to find reference to the alert view, pass the checked option to the select handler, and finally dismiss the view.
So in
ngOnInit
in your component class, you'll need this:Again, if you intend to remove the Cancel button as well, mind the css references in this code.
Changing the API used in the select element (by using the ActionSheet API) could be an option.
In order to do that, you only need to add
interface="action-sheet"
in theion-select
element.I'm not sure if that's a valid option (in terms of UX) in your app.
EDIT:
Just like you can find in Ionic 2 docs