I solved this by creating a method to get Array elements from button array
BTN_ARRAY(dataindex: Array<number>, BTN_ARRAY: any) {
let BTN_OPTION_DRAFT_MORE = [];
BTN_ARRAY.forEach((ele: any, index: number) => {
dataindex.forEach(el => {
if (index === el) {
BTN_OPTION_DRAFT_MORE.push(ele);
}
})
});
return BTN_OPTION_DRAFT_MORE;
}
After that let’s create button actionsheet array like below code:
BTN_OPTION_MORE = [{
text: 'ButtonA',
//icon: 'settings',
handler: () => {
//console.log('ButtonA clicked');
}
});
}
}, {
text: 'ButtonB',
//icon: 'settings',
handler: () => {
//console.log('ButtonB clicked');
}
}, {
text: 'ButtonC',
//icon: 'settings',
handler: () => {
//console.log('ButtonC clicked');
}
}, {
text: 'ButtonD',
role: 'destructive',
handler: () => {
//console.log('ButtonD clicked');
}
});
}
}, {
text: 'Cancel',
role: 'cancel',
handler: () => {
//console.log('Cancel clicked');
}
}];
Now you can show button array what you want by index of button array. let MoreOptions() is the actionsheet function.
async MoreOptions() {
const actionSheet = await this.actCtr.create({
header: 'Options',
buttons: this.BTN_OPTION_MORE_ACTIVE
});
await actionSheet.present();
}
//////Do condition below
if (true) {
this.BTN_OPTION_MORE_ACTIVE = this.BTN_ARRAY([2, 4, 9, 10], this.BTN_OPTION_MORE);
}
else {
this.BTN_OPTION_MORE_ACTIVE = this.shareService.BTN_ARRAY([0,1, 2, 3, 4, 5], this.BTN_OPTION_MORE);
}
Hope can help Thanks.