I\'m trying to execute a Component method from a Service method. I saw these other 2 threads:
Link1 - How to call component met
You can pass a callback to your service and set it as handler for your action sheets.
public presentActionSheet(
actionTitle: string,
items: any[],
callbackHandler:any): void {
let actionSheet = this.actionSheetCtrl.create({
title: actionTitle
});
for (let i = 0; i < items.length; i++) {
actionSheet.addButton({
text: items[i].name,
cssClass: items[i].css,
icon: items[i].selectIcon,
handler: () => {
callbackHandler(i, items[i]);//call the handler passed
console.log('Service ActionHandler');
}
});
}
actionSheet.addButton({ text: 'Cancel', 'role': 'cancel' });
actionSheet.present();
}
In your component
public presentActionSheet(): void {
//calling the service method passing options for the action sheet
this.actionSheetService.presentActionSheet(this.actionTitle,this.types as Type[],this.updateSelectItem.bind(this) );//send your component function. Do not forget to bind the context
}