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

Allow NgModelController to be copied #15836

Merged
merged 2 commits into from
Mar 28, 2017
Merged
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
8 changes: 5 additions & 3 deletions src/ng/directive/ngModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -890,8 +892,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?
Expand Down
23 changes: 23 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<form name="f" undi="[f.i]"><input name="i" ng-model="a"/></form>')($rootScope);
$rootScope.$apply();
expect(componentScope.undi).toBeDefined();
});
});


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