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

Phasecheck #8891

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix(input): check scope.$$phase only on $rootScope
  • Loading branch information
shahata authored and tbosch committed Sep 2, 2014
commit 1e27f5c62a336c7eccfb776d91c83eb60d11d54d
2 changes: 1 addition & 1 deletion src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
// a row.
var revalidate = validity && ctrl.$$hasNativeValidators;
if (ctrl.$viewValue !== value || (value === '' && revalidate)) {
if (scope.$$phase) {
if (scope.$root.$$phase) {
ctrl.$setViewValue(value, event, revalidate);
} else {
scope.$apply(function() {
Expand Down
31 changes: 21 additions & 10 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,19 +1152,30 @@ describe('input', function() {
});

if (!_jqLiteMode) {
it('should not cause the double $digest when triggering an event using jQuery', function() {
$sniffer.hasEvent = function(eventName) {
return eventName !== 'input';
};
describe('double $digest when triggering an event using jQuery', function() {
function run() {
$sniffer.hasEvent = function(eventName) {
return eventName !== 'input';
};

compileInput('<input type="text" ng-model="name" name="alias" ng-change="change()" />');

scope.field = 'fake field';
scope.$watch('field', function() {
// We need to use _originalTrigger since trigger is modified by Angular Scenario.
inputElm._originalTrigger('change');
});
scope.$apply();
}

compileInput('<input type="text" ng-model="name" name="alias" ng-change="change()" />');
it('should not cause the double $digest with non isolate scopes', function() {
run();
});

scope.field = 'fake field';
scope.$watch('field', function() {
// We need to use _originalTrigger since trigger is modified by Angular Scenario.
inputElm._originalTrigger('change');
it('should not cause the double $digest with isolate scopes', function() {
scope = scope.$new(true);
run();
});
scope.$apply();
});
}
});
Expand Down