File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -160,7 +160,7 @@ export class DowngradeNg2ComponentAdapter {
160160 }
161161
162162 registerCleanup ( ) {
163- this . element . bind ( '$remove ' , ( ) => this . viewManager . destroyRootHostView ( this . hostViewRef ) ) ;
163+ this . element . bind ( '$destroy ' , ( ) => this . viewManager . destroyRootHostView ( this . hostViewRef ) ) ;
164164 }
165165}
166166
Original file line number Diff line number Diff line change @@ -230,6 +230,35 @@ export function main() {
230230 } ) ;
231231
232232 } ) ) ;
233+
234+ it ( 'should properly run cleanup when ng1 directive is destroyed' ,
235+ inject ( [ AsyncTestCompleter ] , ( async ) => {
236+ var adapter : UpgradeAdapter = new UpgradeAdapter ( ) ;
237+ var ng1Module = angular . module ( 'ng1' , [ ] ) ;
238+ var onDestroyed : EventEmitter < string > = new EventEmitter < string > ( ) ;
239+
240+ ng1Module . directive ( 'ng1' , ( ) => {
241+ return {
242+ template : '<div ng-if="!destroyIt"><ng2></ng2></div>' ,
243+ controller : function ( $rootScope , $timeout ) {
244+ $timeout ( function ( ) { $rootScope . destroyIt = true ; } ) ;
245+ }
246+ } ;
247+ } ) ;
248+
249+ var Ng2 = Component ( { selector : 'ng2' , template : 'test' } )
250+ . Class ( {
251+ constructor : function ( ) { } ,
252+ ngOnDestroy : function ( ) { onDestroyed . emit ( 'destroyed' ) ; }
253+ } ) ;
254+ ng1Module . directive ( 'ng2' , adapter . downgradeNg2Component ( Ng2 ) ) ;
255+ var element = html ( '<ng1></ng1>' ) ;
256+ adapter . bootstrap ( element , [ 'ng1' ] )
257+ . ready ( ( ref ) => { onDestroyed . subscribe ( ( ) => {
258+ ref . dispose ( ) ;
259+ async . done ( ) ;
260+ } ) } ) ;
261+ } ) ) ;
233262 } ) ;
234263
235264 describe ( 'upgrade ng1 component' , ( ) => {
You can’t perform that action at this time.
0 commit comments