@@ -158,6 +158,7 @@ function $StateRefDirective($state: StateService, $timeout: ITimeoutService) {
158
158
var type = getTypeInfo ( element ) ;
159
159
var active = uiSrefActive [ 1 ] || uiSrefActive [ 0 ] ;
160
160
var unlinkInfoFn : Function = null ;
161
+ var hookFn ;
161
162
162
163
def . options = extend ( defaultOpts ( element , $state ) , attrs . uiSrefOpts ? scope . $eval ( attrs . uiSrefOpts ) : { } ) ;
163
164
@@ -177,7 +178,11 @@ function $StateRefDirective($state: StateService, $timeout: ITimeoutService) {
177
178
update ( ) ;
178
179
179
180
if ( ! type . clickable ) return ;
180
- element . on ( "click" , clickHook ( element , $state , $timeout , type , function ( ) { return def ; } ) ) ;
181
+ hookFn = clickHook ( element , $state , $timeout , type , function ( ) { return def ; } ) ;
182
+ element . bind ( "click" , hookFn ) ;
183
+ scope . $on ( '$destroy' , function ( ) {
184
+ element . unbind ( "click" , hookFn ) ;
185
+ } ) ;
181
186
}
182
187
} ;
183
188
} ] ;
@@ -211,6 +216,7 @@ function $StateRefDynamicDirective($state: StateService, $timeout: ITimeoutServi
211
216
var watch = '[' + group . map ( function ( val ) { return val || 'null' ; } ) . join ( ', ' ) + ']' ;
212
217
var def : Def = { state : null , params : null , options : null , href : null } ;
213
218
var unlinkInfoFn : Function = null ;
219
+ var hookFn ;
214
220
215
221
function runStateRefLink ( group : any [ ] ) {
216
222
def . state = group [ 0 ] ; def . params = group [ 1 ] ; def . options = group [ 2 ] ;
@@ -225,7 +231,11 @@ function $StateRefDynamicDirective($state: StateService, $timeout: ITimeoutServi
225
231
runStateRefLink ( scope . $eval ( watch ) ) ;
226
232
227
233
if ( ! type . clickable ) return ;
228
- element . on ( "click" , clickHook ( element , $state , $timeout , type , function ( ) { return def ; } ) ) ;
234
+ hookFn = clickHook ( element , $state , $timeout , type , function ( ) { return def ; } ) ;
235
+ element . bind ( "click" , hookFn ) ;
236
+ scope . $on ( '$destroy' , function ( ) {
237
+ element . unbind ( "click" , hookFn ) ;
238
+ } ) ;
229
239
}
230
240
} ;
231
241
} ] ;
0 commit comments