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

Commit e1f8a6e

Browse files
committed
fix(ngModel): prevent internal scope reference from being copied
Fixes #15833
1 parent 132d767 commit e1f8a6e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/ng/directive/ngModel.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ function NgModelController($scope, $exceptionHandler, $attr, $element, $parse, $
281281

282282
this.$$currentValidationRunId = 0;
283283

284-
this.$$scope = $scope;
284+
// https://github.com/angular/angular.js/issues/15833
285+
// Prevent `$$scope` from being iterated over by `copy` when NgModelController is deep watched
286+
Object.defineProperty(this, '$$scope', {value: $scope});
285287
this.$$attr = $attr;
286288
this.$$element = $element;
287289
this.$$animate = $animate;

test/ng/compileSpec.js

+23
Original file line numberDiff line numberDiff line change
@@ -5888,6 +5888,29 @@ describe('$compile', function() {
58885888
expect(componentScope.owRef).toEqual({name: 'lucas', item: {name: 'martin'}});
58895889
}));
58905890

5891+
// https://github.com/angular/angular.js/issues/15833
5892+
it('should work with ng-model inputs', function() {
5893+
var componentScope;
5894+
5895+
module(function($compileProvider) {
5896+
$compileProvider.directive('undi', function() {
5897+
return {
5898+
restrict: 'A',
5899+
scope: {
5900+
undi: '<'
5901+
},
5902+
link: function($scope) { componentScope = $scope; }
5903+
};
5904+
});
5905+
});
5906+
5907+
inject(function($compile, $rootScope) {
5908+
element = $compile('<form name="f" undi="[f.i]"><input name="i" ng-model="a"/></form>')($rootScope);
5909+
$rootScope.$apply();
5910+
expect(componentScope.undi).toBeDefined();
5911+
});
5912+
});
5913+
58915914

58925915
it('should not complain when the isolated scope changes', inject(function() {
58935916
compile('<div><span my-component ow-ref="{name: name}">');

0 commit comments

Comments
 (0)