How to set a callback function in ionic?

HI,
I have a reusable view with a “Done” button in the header, I would like to execute different snippet depending on the screen I’m in. So could anyone tell me how to set a callback for “Done” button so that I’ll be able to execute different snippet for different screens.

try to connect the view with a different controller, where you set another done function as ng-click.

Controllers were bounded to their respective views, how could I connect two templates to a single controller?

ah okay now i got it…

then something like this is helping you:

the ion-header-bar takes place in something like a base state/view right? and there you have an ion-nav-view which gets filled by the other states.

so you could add a “done”-function on the button, which triggers a custom angular event:
$scope.$broadcast(‘executeDone’);

And you SubView controller can listen on it and handle it.

so, you are saying to use $scope.on in all controllers where I’m reusing the View?

i thought you have somthing like this:

base page layout with the done button in the headerbar
and then some other states which are in the baselayout

But what do you mean with reusing the “view” is it only the template you reuse?

maybe you can post your “state”-structure with some template snippets.

I haven’t started coding on it yet, I’m just exploring on the ways to do it. If possible I’ll create a sample project with my requirements and share the codepen link. The idea behind reusing view is “I have a contact list which will return list of selected contacts(on clicking Done) and I’ll be using the view in multiple places. So now I would like to do multiple operations with the data depending on the View I’m in(like saving, deleting, sharing)” . Did you get the gist of it?(Note: I don’t want to use localstorage or global variables)

Just to know, Is it not possible to set and get a callback like in JQuery?

Inform you in the docs about Navigation, navbar, navbarbuttons

then you will see you can easy add a “done”-button to views you want (no need to reuse so short parts of code).
And you connect a controller to that view and define a function for the button.

If you not well in that stuff…

Build you app as easy as you can… without reusing stuff and so on.
And if you understand how the concepts are workink you will be able to simplify your code.