@@ -82,6 +82,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
82
82
* the action sheet, or false to keep it opened.
83
83
* - `{function=}` `destructiveButtonClicked` Called when the destructive button is clicked.
84
84
* Return true to close the action sheet, or false to keep it opened.
85
+ * - `{boolean=}` `cancelOnStateChange` Whether to cancel the actionSheet when navigating
86
+ * to a new state. Default true.
85
87
*
86
88
* @returns {function } `hideSheet` A function which, when called, hides & cancels the action sheet.
87
89
*/
@@ -94,14 +96,20 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
94
96
buttonClicked : angular . noop ,
95
97
$deregisterBackButton : angular . noop ,
96
98
buttons : [ ] ,
99
+ cancelOnStateChange : true
97
100
} , opts || { } ) ;
98
101
102
+
99
103
// Compile the template
100
104
var element = scope . element = $compile ( '<ion-action-sheet buttons="buttons"></ion-action-sheet>' ) ( scope ) ;
101
105
102
106
// Grab the sheet element for animation
103
107
var sheetEl = jqLite ( element [ 0 ] . querySelector ( '.action-sheet-wrapper' ) ) ;
104
108
109
+ var stateChangeListenDone = scope . cancelOnStateChange ?
110
+ $rootScope . $on ( '$stateChangeSuccess' , function ( ) { scope . cancel ( ) ; } ) :
111
+ angular . noop ;
112
+
105
113
// removes the actionSheet from the screen
106
114
scope . removeSheet = function ( done ) {
107
115
if ( scope . removed ) return ;
@@ -110,6 +118,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
110
118
sheetEl . removeClass ( 'action-sheet-up' ) ;
111
119
$document [ 0 ] . body . classList . remove ( 'action-sheet-open' ) ;
112
120
scope . $deregisterBackButton ( ) ;
121
+ stateChangeListenDone ( ) ;
122
+ scope . cancel . $scope = null ; //see last line
113
123
114
124
$animate . removeClass ( element , 'active' , function ( ) {
115
125
scope . $destroy ( ) ;
0 commit comments