This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +27
-9
lines changed
2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -495,15 +495,13 @@ var formDirectiveFactory = function(isNgForm) {
495
495
parentFormCtrl . $$renameControl ( controller , alias ) ;
496
496
} ) ;
497
497
}
498
- if ( parentFormCtrl !== nullFormCtrl ) {
499
- formElement . on ( '$destroy' , function ( ) {
500
- parentFormCtrl . $removeControl ( controller ) ;
501
- if ( alias ) {
502
- setter ( scope , alias , undefined , alias ) ;
503
- }
504
- extend ( controller , nullFormCtrl ) ; //stop propagating child destruction handlers upwards
505
- } ) ;
506
- }
498
+ formElement . on ( '$destroy' , function ( ) {
499
+ parentFormCtrl . $removeControl ( controller ) ;
500
+ if ( alias ) {
501
+ setter ( scope , alias , undefined , alias ) ;
502
+ }
503
+ extend ( controller , nullFormCtrl ) ; //stop propagating child destruction handlers upwards
504
+ } ) ;
507
505
}
508
506
} ;
509
507
}
Original file line number Diff line number Diff line change @@ -58,6 +58,26 @@ describe('form', function() {
58
58
expect ( form . alias ) . toBeUndefined ( ) ;
59
59
} ) ;
60
60
61
+ it ( 'should remove scope reference when form with no parent form is removed from the DOM' , function ( ) {
62
+ var formController ;
63
+ scope . ctrl = { } ;
64
+ doc = $compile (
65
+ '<div><form name="ctrl.myForm" ng-if="formPresent">' +
66
+ '<input name="alias" ng-model="value" />' +
67
+ '</form></div>' ) ( scope ) ;
68
+
69
+ scope . $digest ( ) ;
70
+ expect ( scope . ctrl . myForm ) . toBeUndefined ( ) ;
71
+
72
+ scope . $apply ( 'formPresent = true' ) ;
73
+ expect ( scope . ctrl . myForm ) . toBeDefined ( ) ;
74
+
75
+ formController = doc . find ( 'form' ) . controller ( 'form' ) ;
76
+ expect ( scope . ctrl . myForm ) . toBe ( formController ) ;
77
+
78
+ scope . $apply ( 'formPresent = false' ) ;
79
+ expect ( scope . ctrl . myForm ) . toBeUndefined ( ) ;
80
+ } ) ;
61
81
62
82
it ( 'should use ngForm value as form name' , function ( ) {
63
83
doc = $compile (
You can’t perform that action at this time.
0 commit comments