How to use registerBackButtonAction in directive?


#1

I am modifying ion-auto-complete to close the open template on pressing back button.
This is what I am doing:

 var deregister  = $ionicPlatform.registerBackButtonAction(function () {
                            scope.searchQuery = '';
                            $ionicBackdrop.release();
                            el.element.css('display', 'none');
                    }, 300);
 scope.$on('$destroy', deregister)

It is working fine but on page where I am using this directive then back button is not working on that specific page.
Am I doing it wrong?


#2

because navigating back has a priority of 100 and your priority is 300 --> so every backbutton handling with a lower priority gets not called


#3

@bengtler Do you have any suggestion , what should I do in this case where I want backbutton to close template as if template is hide then backbutton should take me to previous page.

Thanks!


#4

derigster your back action on the fly and not only of $destroy is triggered?

like showing the templat --> add your custom backhandling
after you back-handling gets executed --> deregister it