Skip to content

Commit 02e0401

Browse files
committed
Test fixes
1 parent 3c0bddf commit 02e0401

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/directive/model/model.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ export class NgModelController {
237237
/** @internal */
238238
_deregisterModelWatcher: () => void;
239239

240+
/** @internal */
241+
_destroyed: boolean;
242+
240243
/**
241244
* Creates a model controller bound to the element, scope, and ngModel expression.
242245
*/
@@ -296,6 +299,7 @@ export class NgModelController {
296299
this._animate = $animate;
297300
this._parse = $parse;
298301
this._exceptionHandler = $exceptionHandler;
302+
this._destroyed = false;
299303

300304
this._hasNativeValidators = false;
301305
this._classCache = {};
@@ -904,6 +908,10 @@ export class NgModelController {
904908
* usually handles calling this in response to input events.
905909
*/
906910
$commitViewValue() {
911+
if (this._destroyed || !this._element) {
912+
return;
913+
}
914+
907915
clearTimeout(this._pendingDebounce);
908916

909917
// If the view value has not changed then we should just exit, except in the case where there is
@@ -1246,6 +1254,10 @@ export class NgModelController {
12461254
*
12471255
*/
12481256
$processModelValue() {
1257+
if (this._destroyed || !this._element) {
1258+
return;
1259+
}
1260+
12491261
const viewValue = this._format();
12501262

12511263
if (this.$viewValue !== viewValue) {
@@ -1282,6 +1294,10 @@ export class NgModelController {
12821294
*/
12831295
/** @internal */
12841296
_setModelValue(modelValue: any): void {
1297+
if (this._destroyed) {
1298+
return;
1299+
}
1300+
12851301
this.$modelValue = this._rawModelValue = modelValue;
12861302
this._parserValid = undefined;
12871303
this.$processModelValue();
@@ -1429,6 +1445,8 @@ export function ngModelDirective(): ng.Directive {
14291445
})) as () => void;
14301446

14311447
scope.$on("$destroy", () => {
1448+
modelCtrl._destroyed = true;
1449+
14321450
if (modelCtrl._pendingDebounce) {
14331451
clearTimeout(modelCtrl._pendingDebounce);
14341452
modelCtrl._pendingDebounce = undefined;

src/router/directives/view-directive.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,13 @@ export function ViewDirective(
431431
}
432432

433433
if (currentEl) {
434-
const _viewData = getCacheData(
435-
currentEl,
436-
"$ngViewAnim",
437-
) as NgViewAnimData;
434+
const _viewData = getCacheData(currentEl, "$ngViewAnim") as
435+
| NgViewAnimData
436+
| undefined;
438437

439438
trace.traceUIViewEvent("Animate out", activeUIView);
440439
renderer.leave(currentEl, function () {
441-
_viewData.$$animLeave.resolve();
440+
_viewData?.$$animLeave.resolve();
442441
previousEl = null;
443442
});
444443
previousEl = currentEl;

0 commit comments

Comments
 (0)