Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/angular2/src/upgrade/downgrade_ng2_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class DowngradeNg2ComponentAdapter {
}

registerCleanup() {
this.element.bind('$remove', () => this.viewManager.destroyRootHostView(this.hostViewRef));
this.element.bind('$destroy', () => this.viewManager.destroyRootHostView(this.hostViewRef));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: .on() is supposed to be preferred with jQuery.
(Without jQuery, .bind() is just an alias to .on().)

}
}

Expand Down
29 changes: 29 additions & 0 deletions modules/angular2/test/upgrade/upgrade_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,35 @@ export function main() {
});

}));

it('should properly run cleanup when ng1 directive is destroyed',
inject([AsyncTestCompleter], (async) => {
var adapter: UpgradeAdapter = new UpgradeAdapter();
var ng1Module = angular.module('ng1', []);
var onDestroyed: EventEmitter<string> = new EventEmitter<string>();

ng1Module.directive('ng1', () => {
return {
template: '<div ng-if="!destroyIt"><ng2></ng2></div>',
controller: function($rootScope, $timeout) {
$timeout(function() { $rootScope.destroyIt = true; });
}
};
});

var Ng2 = Component({selector: 'ng2', template: 'test'})
.Class({
constructor: function() {},
ngOnDestroy: function() { onDestroyed.emit('destroyed'); }
});
ng1Module.directive('ng2', adapter.downgradeNg2Component(Ng2));
var element = html('<ng1></ng1>');
adapter.bootstrap(element, ['ng1'])
.ready((ref) => {onDestroyed.subscribe(() => {
ref.dispose();
async.done();
})});
}));
});

describe('upgrade ng1 component', () => {
Expand Down