Define a reusable ActionSheet with service/directive

Continuing the discussion from ActionSheet inside directive - strange behaviour:

The problem is, all the demos show a $scope.openActionSheet, but I use the same action sheet in three controllers, I don’t want to define three variables, I want to use a directive to do it. But, seems like actionsheet doesn’t work inside directives today. So, I’m trying to define an actionsheet inside a service and trigger open from a directive… something like that.

How Can I open an ActionSheet from a service?

I made this codepen

Also the log ‘CANCELLED’ appears in the second click.

unfortunately it does not work as you said. But i have a different idea.

create a controller and implement your ActionSheet.
now include/inject the controller everywhere you want your actionsheet.
and call it normal without directive.
you could also inject different buttons, but then i would think about creating a separate ActionSheet

here an example with directive that does not work and with injecting controllers:
http://codepen.io/Auro/pen/MYwOxN?editors=101

Thanks for your help @Auro

This is the only way to get actionsheet to work, but with a directive feels like the better way.

yeah i know bot i was not able to get it to work

Man, I tried a workaround, using controller and directive. (The service is optional), observe that we only use a tag f-options

I create a controller just to deal with the action sheet, and started the controller in the directive’s template. it worked, not so elegant like a meant but, it worked. Codepen

@drew answered the question on GitHub, it solve our problems :slight_smile: https://github.com/driftyco/ionic/issues/2610#issuecomment-64740370