@@ -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 ;
0 commit comments