Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(formController): remove scope reference when form is destroyed
Browse files Browse the repository at this point in the history
Closes #9315
  • Loading branch information
shahata authored and IgorMinar committed Oct 9, 2014
1 parent 9f2ad53 commit 01f50e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/ng/directive/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,13 @@ var formDirectiveFactory = function(isNgForm) {
parentFormCtrl.$$renameControl(controller, alias);
});
}
if (parentFormCtrl !== nullFormCtrl) {
formElement.on('$destroy', function() {
parentFormCtrl.$removeControl(controller);
if (alias) {
setter(scope, alias, undefined, alias);
}
extend(controller, nullFormCtrl); //stop propagating child destruction handlers upwards
});
}
formElement.on('$destroy', function() {
parentFormCtrl.$removeControl(controller);
if (alias) {
setter(scope, alias, undefined, alias);
}
extend(controller, nullFormCtrl); //stop propagating child destruction handlers upwards
});
}
};
}
Expand Down
20 changes: 20 additions & 0 deletions test/ng/directive/formSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ describe('form', function() {
expect(form.alias).toBeUndefined();
});

it('should remove scope reference when form with no parent form is removed from the DOM', function() {
var formController;
scope.ctrl = {};
doc = $compile(
'<div><form name="ctrl.myForm" ng-if="formPresent">' +
'<input name="alias" ng-model="value" />' +
'</form></div>')(scope);

scope.$digest();
expect(scope.ctrl.myForm).toBeUndefined();

scope.$apply('formPresent = true');
expect(scope.ctrl.myForm).toBeDefined();

formController = doc.find('form').controller('form');
expect(scope.ctrl.myForm).toBe(formController);

scope.$apply('formPresent = false');
expect(scope.ctrl.myForm).toBeUndefined();
});

it('should use ngForm value as form name', function() {
doc = $compile(
Expand Down

0 comments on commit 01f50e1

Please sign in to comment.