fix(upgrade): correctly destroy nested downgraded component (#22400)
Previously, when a downgraded component was destroyed in a way that did not trigger the `$destroy` event on the element (e.g. when a parent element was removed from the DOM by Angular, not AngularJS), the `ComponentRef` was not destroyed and unregistered. This commit fixes it by listening for the `$destroy` event on both the element and the scope. Fixes #22392 PR Close #22400
This commit is contained in:

committed by
Alex Eagle

parent
83b32a0a0a
commit
8a85888773
@ -85,15 +85,21 @@ withEachNg1Version(() => {
|
||||
let element: angular.IAugmentedJQuery;
|
||||
|
||||
class mockScope implements angular.IScope {
|
||||
private destroyListeners: (() => void)[] = [];
|
||||
|
||||
$new() { return this; }
|
||||
$watch(exp: angular.Ng1Expression, fn?: (a1?: any, a2?: any) => void) {
|
||||
return () => {};
|
||||
}
|
||||
$on(event: string, fn?: (event?: any, ...args: any[]) => void) {
|
||||
if (event === '$destroy' && fn) {
|
||||
this.destroyListeners.push(fn);
|
||||
}
|
||||
return () => {};
|
||||
}
|
||||
$destroy() {
|
||||
return () => {};
|
||||
let listener: (() => void)|undefined;
|
||||
while ((listener = this.destroyListeners.shift())) listener();
|
||||
}
|
||||
$apply(exp?: angular.Ng1Expression) {
|
||||
return () => {};
|
||||
|
Reference in New Issue
Block a user