From 9c3400677f0722aa3ec2434947150a69e129c45e Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Mon, 20 Mar 2017 22:47:56 -0700 Subject: [PATCH 1/2] refactor(ngModel): use local scope param in watcher --- src/ng/directive/ngModel.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ng/directive/ngModel.js b/src/ng/directive/ngModel.js index 376a6a5f2f4a..02cb6d107727 100644 --- a/src/ng/directive/ngModel.js +++ b/src/ng/directive/ngModel.js @@ -890,8 +890,8 @@ function setupModelWatcher(ctrl) { // -> scope value did not change since the last digest as // ng-change executes in apply phase // 4. view should be changed back to 'a' - ctrl.$$scope.$watch(function ngModelWatch() { - var modelValue = ctrl.$$ngModelGet(ctrl.$$scope); + ctrl.$$scope.$watch(function ngModelWatch(scope) { + var modelValue = ctrl.$$ngModelGet(scope); // if scope model value and ngModel value are out of sync // TODO(perf): why not move this to the action fn? From d104d60f1fadc5530d12974d08654bb44f4715c7 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Mon, 20 Mar 2017 22:49:52 -0700 Subject: [PATCH 2/2] fix(ngModel): prevent internal scope reference from being copied Fixes #15833 --- src/ng/directive/ngModel.js | 4 +++- test/ng/compileSpec.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ng/directive/ngModel.js b/src/ng/directive/ngModel.js index 02cb6d107727..faa36305dd14 100644 --- a/src/ng/directive/ngModel.js +++ b/src/ng/directive/ngModel.js @@ -281,7 +281,9 @@ function NgModelController($scope, $exceptionHandler, $attr, $element, $parse, $ this.$$currentValidationRunId = 0; - this.$$scope = $scope; + // https://github.com/angular/angular.js/issues/15833 + // Prevent `$$scope` from being iterated over by `copy` when NgModelController is deep watched + Object.defineProperty(this, '$$scope', {value: $scope}); this.$$attr = $attr; this.$$element = $element; this.$$animate = $animate; diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index be7d2c13d201..2276df21d698 100644 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -5858,6 +5858,29 @@ describe('$compile', function() { expect(componentScope.owRef).toEqual({name: 'lucas', item: {name: 'martin'}}); })); + // https://github.com/angular/angular.js/issues/15833 + it('should work with ng-model inputs', function() { + var componentScope; + + module(function($compileProvider) { + $compileProvider.directive('undi', function() { + return { + restrict: 'A', + scope: { + undi: '<' + }, + link: function($scope) { componentScope = $scope; } + }; + }); + }); + + inject(function($compile, $rootScope) { + element = $compile('
')($rootScope); + $rootScope.$apply(); + expect(componentScope.undi).toBeDefined(); + }); + }); + it('should not complain when the isolated scope changes', inject(function() { compile('
');