diff --git a/src/ng/directive/ngModel.js b/src/ng/directive/ngModel.js index b9aa13ce13ea..5d73c33ceb28 100644 --- a/src/ng/directive/ngModel.js +++ b/src/ng/directive/ngModel.js @@ -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; @@ -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() { diff --git a/test/ng/directive/ngModelSpec.js b/test/ng/directive/ngModelSpec.js index bc14959ce890..825973bdcf2f 100644 --- a/test/ng/directive/ngModelSpec.js +++ b/test/ng/directive/ngModelSpec.js @@ -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'}; @@ -21,7 +21,6 @@ describe('ngModel', function() { element = jqLite('
'); scope = $rootScope; - ngModelAccessor = jasmine.createSpy('ngModel accessor'); ctrl = $controller(NgModelController, { $scope: scope, $element: element.find('input'), @@ -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'); + }); });