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

fix(input): ensure ngModelWatch() triggers second digest pass when appro... #5282

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
2 changes: 2 additions & 0 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,8 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
ctrl.$render();
}
}

return value;
});
}];

Expand Down
23 changes: 23 additions & 0 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,29 @@ describe('ngModel', function() {
dealoc(element);
});
});

it('should keep previously defined watches consistent when changes in validity are made',
inject(function($compile, $rootScope) {

var isFormValid;
$rootScope.$watch('myForm.$valid', function(value) { isFormValid = value; });

var element = $compile('<form name="myForm">' +
'<input name="myControl" ng-model="value" required >' +
'</form>')($rootScope);

$rootScope.$apply();
expect(isFormValid).toBe(false);
expect($rootScope.myForm.$valid).toBe(false);

$rootScope.value='value';
$rootScope.$apply();
expect(isFormValid).toBe(true);
expect($rootScope.myForm.$valid).toBe(true);

dealoc(element);
}));

});


Expand Down