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

fix(ngModel): do not throw if view value changes on destroyed scope #16585

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ng/directive/ngModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ function NgModelController($scope, $exceptionHandler, $attr, $element, $parse, $
this.$$currentValidationRunId = 0;

this.$$scope = $scope;
this.$$rootScope = $scope.$root;
this.$$attr = $attr;
this.$$element = $element;
this.$$animate = $animate;
Expand Down Expand Up @@ -864,7 +865,7 @@ NgModelController.prototype = {
this.$$pendingDebounce = this.$$timeout(function() {
that.$commitViewValue();
}, debounceDelay);
} else if (this.$$scope.$root.$$phase) {
} else if (this.$$rootScope.$$phase) {
this.$commitViewValue();
} else {
this.$$scope.$apply(function() {
Expand Down
10 changes: 8 additions & 2 deletions test/ng/directive/ngModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('ngModel', function() {

describe('NgModelController', function() {
/* global NgModelController: false */
var ctrl, scope, ngModelAccessor, element, parentFormCtrl;
var ctrl, scope, element, parentFormCtrl;

beforeEach(inject(function($rootScope, $controller) {
var attrs = {name: 'testAlias', ngModel: 'value'};
Expand All @@ -21,7 +21,6 @@ describe('ngModel', function() {
element = jqLite('<form><input></form>');

scope = $rootScope;
ngModelAccessor = jasmine.createSpy('ngModel accessor');
ctrl = $controller(NgModelController, {
$scope: scope,
$element: element.find('input'),
Expand Down Expand Up @@ -438,6 +437,13 @@ describe('ngModel', function() {
expect(ctrl.$modelValue).toBe('c');
expect(scope.value).toBe('c');
}));


it('should not throw an error if the scope has been destroyed', function() {
scope.$destroy();
ctrl.$setViewValue('some-val');
expect(ctrl.$viewValue).toBe('some-val');
});
});


Expand Down